/**
 * Payments Domain - Schemas
 */

import { z } from "zod";

export const paymentMethodTypeSchema = z.enum([
  "CreditCard",
  "BankAccount",
  "RemoteCreditCard",
  "RemoteBankAccount",
  "Manual",
]);

export const paymentMethodSchema = z.object({
  id: z.number().int(),
  type: paymentMethodTypeSchema,
  description: z.string(),
  gatewayName: z.string().optional(),
  contactType: z.string().optional(),
  contactId: z.number().int().optional(),
  cardLastFour: z.string().optional(),
  expiryDate: z.string().optional(),
  startDate: z.string().optional(),
  issueNumber: z.string().optional(),
  cardType: z.string().optional(),
  remoteToken: z.string().optional(),
  lastUpdated: z.string().optional(),
  bankName: z.string().optional(),
  isDefault: z.boolean().optional(),
});

export const paymentMethodListSchema = z.object({
  paymentMethods: z.array(paymentMethodSchema),
  totalCount: z.number().int().min(0),
});

export const paymentGatewayTypeSchema = z.enum([
  "merchant",
  "thirdparty",
  "tokenization",
  "manual",
]);

export const paymentGatewaySchema = z.object({
  name: z.string(),
  displayName: z.string(),
  type: paymentGatewayTypeSchema,
  isActive: z.boolean(),
  configuration: z.record(z.string(), z.unknown()).optional(),
});

export const paymentGatewayListSchema = z.object({
  gateways: z.array(paymentGatewaySchema),
  totalCount: z.number().int().min(0),
});

// ============================================================================
// Inferred Types from Schemas (Schema-First Approach)
// ============================================================================

export type PaymentMethodType = z.infer<typeof paymentMethodTypeSchema>;
export type PaymentMethod = z.infer<typeof paymentMethodSchema>;
export type PaymentMethodList = z.infer<typeof paymentMethodListSchema>;
export type PaymentGatewayType = z.infer<typeof paymentGatewayTypeSchema>;
export type PaymentGateway = z.infer<typeof paymentGatewaySchema>;
export type PaymentGatewayList = z.infer<typeof paymentGatewayListSchema>;
