import { z } from 'zod'

export const slugParamSchema   = z.object({ slug: z.string() })
export const bookingParamSchema = z.object({ slug: z.string(), id: z.string() })

export const availabilitySchema = z.object({
  vehicleId: z.string().cuid(),
  startDate: z.string().datetime(),
  endDate:   z.string().datetime(),
})

export const validateCodeSchema = z.object({ code: z.string().min(1) })

export const bookSchema = z.object({
  vehicleId:     z.string().cuid(),
  startDate:     z.string().datetime(),
  endDate:       z.string().datetime(),
  firstName:     z.string().min(1),
  lastName:      z.string().min(1),
  email:         z.string().email(),
  phone:         z.string().min(1).max(30),
  pickupLocation: z.string().trim().min(1).max(100),
  returnLocation: z.string().trim().min(1).max(100),
  driverLicense: z.string().min(1).max(50).optional(),
  dateOfBirth:   z.string().datetime().optional(),
  licenseExpiry: z.string().datetime().optional(),
  licenseIssuedAt: z.string().datetime().optional(),
  nationality:   z.string().min(1).max(100).optional(),
  identityDocumentNumber: z.string().min(1).max(100).optional(),
  fullAddress: z.string().min(1).max(500).optional(),
  licenseCountry: z.string().min(1).max(100).optional(),
  licenseNumber: z.string().min(1).max(50).optional(),
  licenseCategory: z.string().min(1).max(20).optional(),
  internationalLicenseNumber: z.string().trim().max(100).optional(),
  offerId:       z.string().cuid().optional(),
  promoCodeUsed: z.string().optional(),
  notes:         z.string().optional(),
  source:        z.enum(['PUBLIC_SITE', 'CARPLACE']).default('PUBLIC_SITE'),
  selectedInsurancePolicyIds: z.array(z.string()).default([]),
  additionalDrivers: z.array(z.object({
    firstName:       z.string().min(1),
    lastName:        z.string().min(1),
    email:           z.string().email().optional(),
    phone:           z.string().optional(),
    driverLicense:   z.string().min(1),
    licenseExpiry:   z.string().datetime().optional(),
    licenseIssuedAt: z.string().datetime().optional(),
    dateOfBirth:     z.string().datetime().optional(),
    nationality:     z.string().optional(),
  })).default([]),
})

export const paySchema = z.object({
  provider:   z.enum(['AMANPAY', 'PAYPAL']),
  currency:   z.literal('MAD').default('MAD'),
  successUrl: z.string().url(),
  failureUrl: z.string().url(),
  accessToken: z.string().min(20),
})

export const capturePaypalSchema = z.object({ paypalOrderId: z.string() })

export const contactSchema = z.object({
  name:    z.string().min(1),
  email:   z.string().email(),
  message: z.string().min(1),
})
