/**
 * Zod schemas for payment-method API routes.
 *
 * Boundary schemas only — handler internals (Stripe payment flow) are not touched here.
 */

import { z } from 'zod';
import { paymentBrand } from '@/lib/enums/payment-brand';

const uuidSchema = z.uuid('Must be a valid UUID');

const paymentBrandSchema = paymentBrand.schema;

// ---------------------------------------------------------------------------
// POST /api/payment-methods
// ---------------------------------------------------------------------------

export const createPaymentMethodBodySchema = z.object({
  singleUseToken: z.string().min(1),
  brand: z.string().optional(),
  csrfToken: z.string().min(1).optional(),
});

export type CreatePaymentMethodBody = z.infer<typeof createPaymentMethodBodySchema>;

export const paymentMethodSchema = z.object({
  id: uuidSchema,
  last4: z.string().length(4),
  brand: paymentBrandSchema,
  isDefault: z.boolean(),
});

export type PaymentMethod = z.infer<typeof paymentMethodSchema>;

export const createPaymentMethodResponseSchema = z.object({
  ok: z.literal(true),
  method: paymentMethodSchema,
});

export type CreatePaymentMethodResponse = z.infer<typeof createPaymentMethodResponseSchema>;
