import {z} from 'zod' export type GetApiHotelSearchHotelsHotelIdStaticArgs = {hotel_id: number}; export type GetApiHotelSearchHotelsHotelIdStaticOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const hotelImage = z.object({url: z.string(), category: z.string().nullable().optional(), thumbnail_url: z.string().nullable().optional(), source: z.string().nullable().optional()}); export const descriptionSection = z.object({title: z.string(), paragraphs: z.array(z.string()).optional()}); export const amenityGroup = z.object({group_name: z.string(), amenities: z.array(z.string()).optional()}); export const roomGroup = z.object({name: z.string(), images: z.array(z.string()).optional(), room_amenities: z.array(z.string()).optional(), rg_ext: z.record(z.string(), z.unknown()).nullable().optional(), name_struct: z.record(z.string(), z.unknown()).nullable().optional()}); export const contactInfo = z.object({email: z.string().nullable().optional(), phone: z.string().nullable().optional(), front_desk_time_start: z.string().nullable().optional(), front_desk_time_end: z.string().nullable().optional()}); export const hotelStaticDataResponse = z.object({hotel_id: z.number().int(), etg_provider_id: z.string(), expedia_id: z.number().int().nullable().optional(), name: z.string(), star_rating: z.number().nullable().optional(), review_rating: z.number().nullable().optional(), review_rating_source: z.string().nullable().optional(), address: z.string().nullable().optional(), country_code: z.string().nullable().optional(), latitude: z.number().nullable().optional(), longitude: z.number().nullable().optional(), timezone: z.string().nullable().optional(), check_in_time: z.string().nullable().optional(), check_out_time: z.string().nullable().optional(), images: z.array(hotelImage).optional(), descriptions: z.array(descriptionSection).optional(), amenities: z.array(amenityGroup).optional(), room_groups: z.array(roomGroup).optional(), serp_filters: z.array(z.string()).optional(), policy: z.array(descriptionSection).optional(), payment_methods: z.array(z.string()).optional(), contact: contactInfo.nullable().optional(), facts: z.record(z.string(), z.unknown()).nullable().optional()}); 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 Hotel Static Data * * GET /hotel-search/hotels/{hotel_id}/static */ export const getApiHotelSearchHotelsHotelIdStatic = async (args: GetApiHotelSearchHotelsHotelIdStaticArgs, options: GetApiHotelSearchHotelsHotelIdStaticOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/hotel-search/hotels/${encodeURIComponent(String(args.hotel_id))}/static${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(hotelStaticDataResponse, await res.json()) };