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),
  driverLicense: z.string().min(1).max(50),
  dateOfBirth:   z.string().datetime(),
  licenseExpiry: z.string().datetime(),
  licenseIssuedAt: z.string().datetime(),
  nationality:   z.string().min(1).max(100),
  identityDocumentNumber: z.string().min(1).max(100),
  fullAddress: z.string().min(1).max(500),
  licenseCountry: z.string().min(1).max(100),
  licenseNumber: z.string().min(1).max(50).optional(),
  licenseCategory: z.string().min(1).max(20),
  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', 'MARKETPLACE']).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(),
})

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),
})
