import { z } from "zod";
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({
        pIntentId: z.string(),
        paymentId: zPagamentoId,
      }),
    )
    .query(async ({ input }) => {
      return await whIntentCreatedHandler({
        pIntentId: input.pIntentId,
        paymentId: input.paymentId,
      });
    }),

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