import { dataInsert } from '@opengis/fastify-table/utils.js';

export default async function addNotification({
  pg, user = {}, subject, body, link, uid, entity,
}) {
  const { uid: author } = user || {};
  const res = await dataInsert({
    pg,
    table: 'crm.notifications',
    data: {
      subject,
      body,
      link,
      addressee_id: uid,
      author_id: author,
      entity_id: entity,
      uid: author,
    },
  });
  return res?.rows?.[0] || {};
}
