import { z } from "zod";
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";
import { zUserId } from "~/server/utils/zod_types";
import { genMail, type MailsTemplates } from "~/server/services/mailer";
import { GetEmails, StoreEmail } from "~/server/services/email.service";

export const comunicazioniRouter = createTRPCRouter({
  storeEmail: publicProcedure
    .input(
      z.object({
        userId: zUserId,
        data: z.custom<MailsTemplates>(),
      }),
    )
    .mutation(async ({ input }) => {
      return await StoreEmail({
        userId: input.userId,
        data: input.data,
      });
    }),
  getEmails: publicProcedure
    .input(z.object({ userId: zUserId }))
    .query(async ({ input }) => {
      return await GetEmails({
        userId: input.userId,
      });
    }),
  genEmail: publicProcedure
    .input(
      z.object({
        mail: z.custom<MailsTemplates>(),
      }),
    )
    .query(async ({ input }) => {
      return await genMail({
        ...input.mail,
      });
    }),
});
