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

export const stripeRouter = createTRPCRouter({
	health: publicProcedure.query(async () => {
		return await stripeHealthCheck();
	}),
	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(),
				pm_id: z.string(),
			}),
		)
		.query(async ({ input }) => {
			return await whIntentCreatedHandler({
				paymentId: input.paymentId,
				pIntentId: input.pIntentId,
				pm_id: input.pm_id,
			});
		}),
	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,
			});
		}),
});

/*
Credit Card integration guide
https://docs.stripe.com/payments/cards

Google Pay integration guide
https://docs.stripe.com/google-pay

SEPA Direct Debit integration guide
https://docs.stripe.com/payments/sepa-debit/accept-a-payment

Bank Transfers integration guide
https://docs.stripe.com/payments/bank-transfers

Satispay integration guide
https://docs.stripe.com/payments/satispay
*/
