const moment = require("moment");
const { tinytom } = require("./message.helper");
const messages = require("./messages.json");

const createNotification = (data) => {
  return {
    date: data.date,
    title: data.title,
    body: data.body,
    ttl: data.ttl,
    priority: data.priority ? data.priority : "high",
    recipients: data.recipients,
    data: data.data,
    userId: data.userId,
  };
};

const createNotificationValidatedInscription = (inscription) => {
  let jsonMessage = messages.push.confirmInvitation;

  const jsonNotification = tinytom(jsonMessage, {
    congress: inscription.event.name,
    ticketId: inscription.id,
  });

  return {
    ...jsonNotification,
    date: moment(),
    priority: "high",
    recipients: {
      userIds: [inscription.user.id],
    },
  };
};

module.exports = {
  createNotificationValidatedInscription,
  createNotification,
  //createMessageNotification
};
