import { router, protectedProcedure } from "@/src/trpc/trpc-index"
import { z } from "zod";

const initiateRefundSchema = z
  .object({
    orderId: z.number(),
    refundPercent: z.number().min(0).max(100).optional(),
    refundAmount: z.number().min(0).optional(),
  })
  .refine(
    (data) => {
      const hasPercent = data.refundPercent !== undefined;
      const hasAmount = data.refundAmount !== undefined;
      return (hasPercent && !hasAmount) || (!hasPercent && hasAmount);
    },
    {
      message:
        "Provide either refundPercent or refundAmount, not both or neither",
    }
  );

export const adminPaymentsRouter = router({
  initiateRefund: protectedProcedure
    .input(initiateRefundSchema)
    .mutation(async ({ input }) => {
      return {}
    }),
});
