import { z } from "zod/v4";

import {
	adminProcedure,
	createTRPCRouter,
	protectedProcedure,
	publicProcedure,
} from "~/server/api/trpc";
import {
	addClient,
	getClientFromCF,
	getClientList,
	searchClient,
} from "~/server/controllers/fic.controller";
import { ClientSchema } from "~/server/services/fic.service";

export const fattureRouter = createTRPCRouter({
	createClient: protectedProcedure
		.input(
			z.object({
				client: ClientSchema,
			}),
		)
		.mutation(async ({ input }) => {
			return await addClient(input.client);
		}),
	getClientFromCF: publicProcedure
		.input(
			z.object({
				cf: z.string(),
			}),
		)
		.query(async ({ input }) => {
			return await getClientFromCF(input.cf);
		}),
	getListClienti: adminProcedure.query(async () => {
		return await getClientList();
	}),
	searchClient: adminProcedure
		.input(
			z.object({
				cognome: z.string(),
			}),
		)
		.query(async ({ input }) => {
			return await searchClient(input.cognome);
		}),
});
