import { z } from "zod/v4";
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({
				cognome: z.string(),
				email: z.email(),
				messaggio: z.string(),
				nome: z.string(),
				telefono: z.string(),
			}),
		)
		.mutation(async ({ input }) => {
			await NewMail({
				template: {
					mailType: "contattoAdminEmail",
					props: {
						cognome: input.cognome,
						email: input.email,
						messaggio: input.messaggio,
						nome: input.nome,
						telefono: input.telefono,
					},
				},
				mail: {
					subject: `Richiesta di contatto da ${input.nome}`,
					to: "web@infoalloggi.it",
				},
			});
			return { success: true };
		}),
});
