import {z} from 'zod' export type GetApiHotelSearchBookingSessionsResumeArgs = {hotel_id: number, quote_id: string, check_in: string, check_out: string}; export type GetApiHotelSearchBookingSessionsResumeOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const money = z.object({amount: z.number().int(), currency: z.string()}); export const hotelPriceBreakdown = z.object({nights: z.number().int(), nightly_rate_cents: z.number().int(), nightly_rate_currency: z.string(), subtotal_cents: z.number().int(), fees_at_property_cents: z.number().int().nullable().optional(), fees_at_property_currency: z.string().nullable().optional(), total_cents: z.number().int().nullable().optional(), total_currency: z.string().nullable().optional()}); export const hotelSearchBookingSessionResponse = z.object({id: z.string(), hotel_search_session_id: z.string().nullable().optional(), flight_hotel_obligation_id: z.string().nullable().optional(), user_id: z.string(), hotel_id: z.number().int(), quote_id: z.string(), check_in: z.string(), check_out: z.string(), checkout_step: z.enum(["review", "guests", "membership", "payment", "processing", "confirmed", "failed"]), status: z.enum(["active", "processing", "completed", "failed", "abandoned"]), is_valid: z.boolean(), payload: z.record(z.string(), z.unknown()), booking_id: z.string().nullable(), hotel_purchase_id: z.string().nullable(), confirmation_code: z.string().nullable(), failure_reason: z.string().nullable(), replacement_for_booking_id: z.string().nullable().optional(), conv_trip_id: z.string().nullable().optional(), contact_email: z.string().nullable().optional(), hotel_name: z.string().nullable().optional(), room_type: z.string().nullable().optional(), price_amount: z.number().int().nullable().optional(), price_currency: z.string().nullable().optional(), cancellation_policy: z.string().nullable().optional(), fees_at_property_amount: z.number().int().nullable().optional(), fees_at_property_currency: z.string().nullable().optional(), retail_price_amount: z.number().int().nullable().optional(), retail_price_currency: z.string().nullable().optional(), guest_names: z.array(z.string()).optional(), created_at: z.string(), updated_at: z.string(), price: money.nullable(), fees_at_property: money.nullable(), retail_price: money.nullable(), price_breakdown: hotelPriceBreakdown.nullable()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get Resumable Hotel Search Booking Session * * GET /hotel-search/booking-sessions/resume */ export const getApiHotelSearchBookingSessionsResume = async (args: GetApiHotelSearchBookingSessionsResumeArgs, options: GetApiHotelSearchBookingSessionsResumeOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.hotel_id != null) query.append("hotel_id", String(args.hotel_id)) if (args.quote_id != null) query.append("quote_id", String(args.quote_id)) if (args.check_in != null) query.append("check_in", String(args.check_in)) if (args.check_out != null) query.append("check_out", String(args.check_out)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/hotel-search/booking-sessions/resume${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(hotelSearchBookingSessionResponse, await res.json()) };