import { z } from "zod";
import { paymentInfoModel } from "../../paymentinfo/data/entities";

export enum Gender {
  Male = "male",
  Female = "female",
  Other = "other",
}

export enum PassengerType {
  Adult = "adult",
  Child = "child",
}

export const customerInfoModel = z.object({
  firstName: z.string().min(1).max(255),
  middleName: z.string().min(0).max(255),
  lastName: z.string().min(1).max(255),
  email: z.string().email(),
  phoneCountryCode: z.string().min(2).max(6).regex(/^\+/),
  phoneNumber: z.string().min(2).max(20),
  nationality: z.string().min(1).max(128),
  gender: z.enum([Gender.Male, Gender.Female, Gender.Other]),
  dob: z.string().date(),
  passportNo: z.string().min(1).max(64),
  // add a custom validator to ensure this is not expired (present or older)
  passportExpiry: z
    .string()
    .date()
    .refine(
      (v) => new Date(v).getTime() > new Date().getTime(),
      "Passport expiry must be in the future",
    ),

  country: z.string().min(1).max(128),
  state: z.string().min(1).max(128),
  city: z.string().min(1).max(128),
  zipCode: z.string().min(4).max(21),
  address: z.string().min(1).max(128),
  address2: z.string().min(0).max(128),
});
export type CustomerInfo = z.infer<typeof customerInfoModel>;

export const passengerInfoModel = z.object({
  id: z.number(),
  passengerType: z.enum([PassengerType.Adult, PassengerType.Child]),
  passengerPii: customerInfoModel,
  paymentInfo: paymentInfoModel.optional(),
  passengerPiiId: z.number().optional(),
  paymentInfoId: z.number().optional(),
  seatSelection: z.any(),
  bagSelection: z.any(),

  agentsInfo: z.boolean().default(false).optional(),
  agentId: z.coerce.string().optional(),
  flightTicketInfoId: z.number().optional(),
  orderId: z.number().optional(),
});
export type PassengerInfo = z.infer<typeof passengerInfoModel>;
