import {z} from 'zod' export type GetApiBookingV1ReservationsCountArgs = {bookingId?: string | undefined, propertyIds?: Array | undefined, ratePlanIds?: Array | undefined, companyIds?: Array | undefined, unitIds?: Array | undefined, unitGroupIds?: Array | undefined, unitGroupTypes?: (Array<'BedRoom' | 'MeetingRoom' | 'EventSpace' | 'ParkingLot' | 'Other'>) | undefined, blockIds?: Array | undefined, marketSegmentIds?: Array | undefined, status?: (Array<'Confirmed' | 'InHouse' | 'CheckedOut' | 'Canceled' | 'NoShow'>) | undefined, dateFilter?: ('Arrival' | 'Departure' | 'Stay' | 'Creation' | 'Modification' | 'Cancellation' | 'ArrivalAndCheckIn' | 'DepartureAndCheckOut') | undefined, from?: string | undefined, to?: string | undefined, channelCode?: (Array<'Direct' | 'BookingCom' | 'Ibe' | 'ChannelManager' | 'Expedia' | 'Homelike' | 'Hrs' | 'AltoVita' | 'DesVu' | 'Gimsi'>) | undefined, sources?: Array | undefined, validationMessageCategory?: (Array<'OfferNotAvailable' | 'AutoUnitAssignment' | 'GuestLoyalty'>) | undefined, externalCode?: string | undefined, textSearch?: string | undefined, balanceFilter?: Array | undefined, allFoliosHaveInvoice?: boolean | undefined, isPreCheckedIn?: boolean | undefined, hasActivePaymentAccount?: boolean | undefined, externalReferences?: Array | undefined}; export type GetApiBookingV1ReservationsCountOptions = {baseUrl: string, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const countModel = z.object({count: z.number().int()}); 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 }; /** * Returns the number of reservations fulfilling the criteria specified in the parameters. * * GET /booking/v1/reservations/$count */ export const getApiBookingV1ReservationsCount = async (args: GetApiBookingV1ReservationsCountArgs, options: GetApiBookingV1ReservationsCountOptions) => { const {baseUrl, fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.bookingId != null) query.append("bookingId", String(args.bookingId)) for (const item of args.propertyIds ?? []) query.append("propertyIds", String(item)) for (const item of args.ratePlanIds ?? []) query.append("ratePlanIds", String(item)) for (const item of args.companyIds ?? []) query.append("companyIds", String(item)) for (const item of args.unitIds ?? []) query.append("unitIds", String(item)) for (const item of args.unitGroupIds ?? []) query.append("unitGroupIds", String(item)) for (const item of args.unitGroupTypes ?? []) query.append("unitGroupTypes", String(item)) for (const item of args.blockIds ?? []) query.append("blockIds", String(item)) for (const item of args.marketSegmentIds ?? []) query.append("marketSegmentIds", String(item)) for (const item of args.status ?? []) query.append("status", String(item)) if (args.dateFilter != null) query.append("dateFilter", String(args.dateFilter)) if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) for (const item of args.channelCode ?? []) query.append("channelCode", String(item)) for (const item of args.sources ?? []) query.append("sources", String(item)) for (const item of args.validationMessageCategory ?? []) query.append("validationMessageCategory", String(item)) if (args.externalCode != null) query.append("externalCode", String(args.externalCode)) if (args.textSearch != null) query.append("textSearch", String(args.textSearch)) for (const item of args.balanceFilter ?? []) query.append("balanceFilter", String(item)) if (args.allFoliosHaveInvoice != null) query.append("allFoliosHaveInvoice", String(args.allFoliosHaveInvoice)) if (args.isPreCheckedIn != null) query.append("isPreCheckedIn", String(args.isPreCheckedIn)) if (args.hasActivePaymentAccount != null) query.append("hasActivePaymentAccount", String(args.hasActivePaymentAccount)) for (const item of args.externalReferences ?? []) query.append("externalReferences", String(item)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/booking/v1/reservations/$count${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(countModel, await res.json()) };