const prisma = require("./prismaClient");

// Subscription
const postEmailSub = async (email) => {
  const checkMail = await prisma.subscribers.findUnique({
    where: {
      email: email,
    },
  });

  if (!checkMail) {
    const res = await prisma.subscribers.create({
      data: {
        email: email,
      },
    });
    return res;
  } else {
    return "exist";
  }
};

// Contact Message
const postContactMessage = async ({ name, number, email, message }) => {
  try {
    const res = await prisma.messages.create({
      data: {
        email: email,
        name: name,
        phone: number,
        message: message,
      },
    });
    return res;
  } catch (error) {
    throw new Error();
  }
};

module.exports = {
  postEmailSub,
  postContactMessage,
};
