import {z} from 'zod' export type LodgifyApiPublicReservationsModelsV12GuestBreakdownDto = {adults?: number | undefined, children?: number | undefined, infants?: number | undefined, pets?: number | undefined}; export type LodgifyApiPublicReservationsModelsV1GuestNameDto = {first_name?: (string | null) | undefined, last_name?: (string | null) | undefined, full_name?: (string | null) | undefined}; export type LodgifyApiPublicReservationsModelsV1CreateBookingGuestDto = {guest_name: LodgifyApiPublicReservationsModelsV1GuestNameDto, name?: (string | null) | undefined, external_id?: (string | null) | undefined, email?: (string | null) | undefined, phone?: (string | null) | undefined, locale?: (string | null) | undefined, street_address1?: (string | null) | undefined, street_address2?: (string | null) | undefined, city?: (string | null) | undefined, country_code?: (string | null) | undefined, postal_code?: (string | null) | undefined, state?: (string | null) | undefined}; export type LodgifyApiPublicReservationsModelsV1BookingThreadMessageTypeDto = 'Owner' | 'Comment' | 'Renter'; export type LodgifyApiPublicReservationsModelsV1CreateBookingMessageDto = {subject?: (string | null) | undefined, message?: (string | null) | undefined, type?: LodgifyApiPublicReservationsModelsV1BookingThreadMessageTypeDto | undefined, send_notification?: boolean | undefined}; export type LodgifyApiPublicReservationsModelsV1CreateEnquiryDto = {source_text?: (string | null) | undefined, source_address?: (string | null) | undefined, arrival?: (string | null) | undefined, departure?: (string | null) | undefined, guest_breakdown: LodgifyApiPublicReservationsModelsV12GuestBreakdownDto, people?: (number | null) | undefined, property_id?: (number | null) | undefined, room_type_id?: (number | null) | undefined, guest?: LodgifyApiPublicReservationsModelsV1CreateBookingGuestDto | undefined, messages?: (Array | null) | undefined, status?: (string | null) | undefined, has_privacy_consent?: (boolean | null) | undefined, ip_created?: (string | null) | undefined, origin?: (string | null) | undefined, thread_id?: (string | null) | undefined}; export type CreateApiV1ReservationEnquiryArgs = {body: LodgifyApiPublicReservationsModelsV1CreateEnquiryDto}; export type CreateApiV1ReservationEnquiryOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1ReservationEnquiryResponse = 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 }; /** * Creates a new general enquiry. * * POST /v1/reservation/enquiry */ export const createApiV1ReservationEnquiry = async (args: CreateApiV1ReservationEnquiryArgs, options?: CreateApiV1ReservationEnquiryOptions) => { const {baseUrl = "https://api.lodgify.com", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set("X-ApiKey", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/reservation/enquiry${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiV1ReservationEnquiryResponse, await res.json()) };