import { protectedProcedure } from "$lib/server/trpc/t";
import { createTRPCRouter } from "$lib/trpc/t";
import { z } from "zod";
import { createCustomerInfoPayload, updateCustomerInfoPayload } from "./data";
import { getCustomerInfoUseCases } from "./usecases";

export const customerInfoRouter = createTRPCRouter({
	getAllCustomerInfo: protectedProcedure.query(async ({}) => {
		const controller = getCustomerInfoUseCases();
		return controller.getAllCustomerInfo();
	}),

	getCustomerInfoById: protectedProcedure
		.input(z.object({ id: z.number() }))
		.query(async ({ input }) => {
			const controller = getCustomerInfoUseCases();
			return controller.getCustomerInfoById(input.id);
		}),

	createCustomerInfo: protectedProcedure
		.input(createCustomerInfoPayload)
		.mutation(async ({ input }) => {
			const controller = getCustomerInfoUseCases();
			return controller.createCustomerInfo(input);
		}),

	updateCustomerInfo: protectedProcedure
		.input(updateCustomerInfoPayload)
		.mutation(async ({ input }) => {
			const controller = getCustomerInfoUseCases();
			return controller.updateCustomerInfo(input);
		}),

	deleteCustomerInfo: protectedProcedure
		.input(z.object({ id: z.number() }))
		.mutation(async ({ input }) => {
			const controller = getCustomerInfoUseCases();
			return controller.deleteCustomerInfo(input.id);
		}),
});
