import { z } from "zod"; import { CabinClass, TicketType } from "./enums"; export * from "./enums"; export const stationModel = z.object({ id: z.number(), type: z.string(), code: z.string(), name: z.string(), city: z.string(), country: z.string(), }); export type Station = z.infer; export const iteneraryStationModel = z.object({ station: stationModel, localTime: z.string(), utcTime: z.string(), }); export type IteneraryStation = z.infer; export const seatInfoModel = z.object({ availableSeats: z.number(), seatClass: z.string(), }); export type SeatInfo = z.infer; export const flightPriceDetailsModel = z.object({ currency: z.string(), basePrice: z.number(), discountAmount: z.number(), displayPrice: z.number(), orderPrice: z.number().nullable().optional(), appliedCoupon: z.string().nullish().optional(), couponDescription: z.string().nullish().optional(), }); export type FlightPriceDetails = z.infer; export const airlineModel = z.object({ code: z.string(), name: z.string(), imageUrl: z.string().nullable().optional(), }); export type Airline = z.infer; export const flightIteneraryModel = z.object({ flightId: z.string(), flightNumber: z.string(), airline: airlineModel, departure: iteneraryStationModel, destination: iteneraryStationModel, durationSeconds: z.number(), seatInfo: seatInfoModel, }); export type FlightItenerary = z.infer; export const passengerCountModel = z.object({ adults: z.number().int().min(0), children: z.number().int().min(0), }); export type PassengerCount = z.infer; export function countPassengers(model: PassengerCount) { return model.adults + model.children; } export const bagDimensionsModel = z.object({ length: z.number(), width: z.number(), height: z.number(), }); export type BagDimensions = z.infer; export const bagDetailsModel = z.object({ price: z.number(), weight: z.number(), unit: z.string(), dimensions: bagDimensionsModel, }); export type BagDetails = z.infer; export const allBagDetailsModel = z.object({ personalBags: bagDetailsModel, handBags: bagDetailsModel, checkedBags: bagDetailsModel, }); export type AllBagDetails = z.infer; // INFO: If you are to array-ificate it, you can just modify the details // key below so that the user's order thing is not disrupted export const bagsInfoModel = z.object({ includedPersonalBags: z.number().default(1), includedHandBags: z.number().default(0), includedCheckedBags: z.number().default(0), hasHandBagsSupport: z.boolean().default(true), hasCheckedBagsSupport: z.boolean().default(true), details: allBagDetailsModel, }); export type BagsInfo = z.infer; export const flightTicketModel = z.object({ id: z.number().int(), ticketId: z.string(), // For lookup purposes, we need these on the top level departure: z.string(), arrival: z.string(), departureDate: z.coerce.string(), returnDate: z.coerce.string().default(""), dates: z.array(z.string()), flightType: z.enum([TicketType.OneWay, TicketType.Return]), flightIteneraries: z.object({ outbound: z.array(flightIteneraryModel), inbound: z.array(flightIteneraryModel), }), priceDetails: flightPriceDetailsModel, refundable: z.boolean(), passengerCounts: passengerCountModel, cabinClass: z.string(), bagsInfo: bagsInfoModel, lastAvailable: z.object({ availableSeats: z.number() }), shareId: z.string(), checkoutUrl: z.string(), isCache: z.boolean().nullish().optional(), refOIds: z.array(z.coerce.number()).nullish().optional(), createdAt: z.coerce.string(), updatedAt: z.coerce.string(), }); export type FlightTicket = z.infer; export const limitedFlightTicketModel = flightTicketModel.pick({ id: true, departure: true, arrival: true, departureDate: true, returnDate: true, flightType: true, dates: true, priceDetails: true, passengerCounts: true, cabinClass: true, }); export type LimitedFlightTicket = z.infer; // INFO: ticket search models export const ticketSearchPayloadModel = z.object({ sessionId: z.string(), ticketType: z.enum([TicketType.OneWay, TicketType.Return]), cabinClass: z.enum([ CabinClass.Economy, CabinClass.PremiumEconomy, CabinClass.Business, CabinClass.FirstClass, ]), departure: z.string().min(3), arrival: z.string().min(3), passengerCounts: passengerCountModel, departureDate: z.coerce.string().min(3), returnDate: z.coerce.string(), loadMore: z.boolean().default(false), meta: z.record(z.string(), z.any()).optional(), couponCode: z.string().optional(), }); export type TicketSearchPayload = z.infer; export const ticketSearchDTO = z.object({ sessionId: z.string(), ticketSearchPayload: ticketSearchPayloadModel, providers: z.array(z.string()).optional(), }); export type TicketSearchDTO = z.infer;