import { z } from 'zod'
import { textField, optionalTextField, emailField, optionalUpperField, optionalPhoneField } from '../../lib/zodValidation'

export const paginationSchema = z.object({
  page:     z.coerce.number().int().min(1).max(10000).default(1),
  pageSize: z.coerce.number().int().min(1).max(100).default(20),
})

export const customerSchema = z.object({
  firstName:       textField('name'),
  lastName:        textField('name'),
  email:           emailField(),
  phone:           optionalPhoneField(),
  driverLicense:   optionalUpperField('driverLicenseNumber'),
  dateOfBirth:     z.string().datetime().optional(),
  nationality:     optionalTextField('nationality'),
  address:         z.record(z.unknown()).optional(),
  notes:           z.string().max(2000).trim().optional(),
  licenseExpiry:   z.string().datetime().optional(),
  licenseIssuedAt: z.string().datetime().optional(),
  licenseCountry:  optionalTextField('country'),
  licenseNumber:   optionalUpperField('driverLicenseNumber'),
  licenseCategory: optionalUpperField('licenseCategory'),
})

export const listQuerySchema = paginationSchema.extend({
  q:       z.string().max(100).optional(),
  flagged: z.enum(['true', 'false']).optional(),
})

export const approveLicenseSchema = z.object({
  decision: z.enum(['APPROVE', 'DENY']),
  note:     z.string().optional(),
})

export const flagSchema = z.object({
  reason: z.string().optional(),
})

export const idParamSchema = z.object({ id: z.string() })
