import { z } from "zod/v4";
import {
	createTRPCRouter,
	protectedProcedure,
	publicProcedure,
} from "~/server/api/trpc";
import {
	createIntentHandler,
	whIntentCreatedHandler,
	whIntentFailedHandler,
	whIntentSucceededHandler,
} from "~/server/controllers/stripe.controller";
import { zPagamentoId } from "~/server/utils/zod_types";

export const stripeRouter = createTRPCRouter({
	createIntent: protectedProcedure
		.input(
			z.object({
				paymentId: zPagamentoId,
			}),
		)
		.mutation(async ({ input }) => {
			return await createIntentHandler({
				paymentId: input.paymentId,
			});
		}),
	whIntentCreated: publicProcedure
		.input(
			z.object({
				paymentId: zPagamentoId,
				pIntentId: z.string(),
			}),
		)
		.query(async ({ input }) => {
			return await whIntentCreatedHandler({
				paymentId: input.paymentId,
				pIntentId: input.pIntentId,
			});
		}),
	whIntentFailed: publicProcedure
		.input(z.object({ pIntentId: z.string() }))
		.query(async ({ input }) => {
			return await whIntentFailedHandler({
				pIntentId: input.pIntentId,
			});
		}),

	whIntentSucceeded: publicProcedure
		.input(
			z.object({
				paymentId: zPagamentoId,
				pIntentId: z.string(),
				pm_id: z.string(),
			}),
		)
		.query(async ({ input }) => {
			return await whIntentSucceededHandler({
				paymentId: input.paymentId,
				pIntentId: input.pIntentId,
				pm_id: input.pm_id,
			});
		}),
});
