import { z } from "zod";
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";
import { NewMail } from "~/server/services/mailer";
// Create a new ratelimiter, that allows 10 requests per 10 seconds
/*
const ratelimit = new RateLimiterHandler({
  windowSize: 10,
  maxRequests: 10,
  analytics: true,
});
*/
export const contactRouter = createTRPCRouter({
  postContact: publicProcedure
    .input(
      z.object({
        nome: z.string(),
        cognome: z.string(),
        email: z.string().email(),
        telefono: z.string(),
        messaggio: z.string(),
      }),
    )
    .mutation(async ({ input }) => {
      await NewMail({
        to: "web@infoalloggi.it",
        subject: `Richiesta di contatto da ${input.nome}`,
        mailType: "contattoAdminEmail",
        props: {
          nome: input.nome,
          cognome: input.cognome,
          email: input.email,
          telefono: input.telefono,
          messaggio: input.messaggio,
        },
      });
      return { success: true };
    }),
});
