import {z} from 'zod' export type LodgifyApiPublicReservationsModelsV12GuestBreakdownDto = {adults?: number | undefined, children?: number | undefined, infants?: number | undefined, pets?: number | undefined}; export type LodgifyApiPublicReservationsModelsV2QuoteRoomTypeParamDto = {id?: number | undefined, guest_breakdown: LodgifyApiPublicReservationsModelsV12GuestBreakdownDto, people?: number | undefined}; export type LodgifyApiPublicReservationsModelsV2QuoteAddOnParamDto = {id?: number | undefined, units?: (number | null) | undefined}; export type GetApiV2QuotePropertyIdArgs = {arrival?: string | undefined, departure?: string | undefined, propertyId: number, roomTypes?: Array | undefined, addOns?: Array | undefined, promotionCode?: string | undefined}; export type GetApiV2QuotePropertyIdOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const lodgifyApiPublicReservationsModelsV2QuoteQuoteItemType = z.enum(["RoomRate", "Promotion", "Fee", "AddOn", "Tax", "Other"]); export const lodgifyApiPublicReservationsModelsV2QuoteFeeType = z.enum(["Cleaning", "Miscellaneous", "DamageProtectionInsurance", "ManagementFee", "ServiceFee", "Wood", "DrinkingWater", "WaterCraftMooring", "WaterCraft", "Water", "Vehicle", "FoodUtensils", "UtensilsCleaning", "Transportation", "Tour", "Toiletries", "Spa", "Resort", "Rent", "Parking", "Phone", "OnSitePaymentMethod", "Oil", "LinensBed", "LinensBath", "Linens", "Laundry", "Labor", "Internet", "TravelInsurance", "HotTub", "HighChair", "Heating", "Gas", "Gardening", "Food", "Equipment", "Electricity", "Concierge", "PoolHeating", "Pool", "Class", "BabyBed", "PropertyAssociation", "AirConditioning", "AdditionalBed", "PetFee", "ServiceCharge", "GratuityFee", "DamageWaiver", "Community"]); export const lodgifyApiPublicReservationsModelsV2QuoteRoomRateType = z.enum(["Stay", "ShortStayPremium"]); export const lodgifyApiPublicReservationsModelsV2QuoteQuotePriceDto = z.object({uid: z.string().nullable().optional(), description: z.string().nullable().optional(), amount: z.number().optional(), fee_type: lodgifyApiPublicReservationsModelsV2QuoteFeeType.optional(), room_rate_type: lodgifyApiPublicReservationsModelsV2QuoteRoomRateType.optional()}); export const lodgifyApiPublicReservationsModelsV2QuoteQuotePriceTypeDto = z.object({type: lodgifyApiPublicReservationsModelsV2QuoteQuoteItemType.optional(), is_negative: z.boolean().optional(), description: z.string().nullable().optional(), prices: z.array(lodgifyApiPublicReservationsModelsV2QuoteQuotePriceDto).nullable().optional(), subtotal: z.number().optional()}); export const lodgifyApiPublicReservationsModelsV2QuoteQuoteRoomTypeDto = z.object({room_type_id: z.number().int().optional(), name: z.string().nullable().optional(), people: z.number().int().optional(), price_types: z.array(lodgifyApiPublicReservationsModelsV2QuoteQuotePriceTypeDto).nullable().optional(), subtotal: z.number().optional()}); export const lodgifyApiPublicReservationsModelsV2QuoteQuoteAddOnDto = z.object({add_on_id: z.number().int().optional(), name: z.string().nullable().optional(), units: z.number().int().nullable().optional(), amount: z.number().optional()}); export const lodgifyApiPublicReservationsModelsV2QuoteQuoteOtherItemDto = z.object({type: z.string().nullable().optional(), description: z.string().nullable().optional(), amount: z.number().optional()}); export const lodgifyApiPublicReservationsModelsV2QuoteQuoteScheduledTransactionDto = z.object({type: z.string().nullable().optional(), date_due: z.string().nullable().optional(), amount: z.number().optional(), is_current: z.boolean().optional(), status: z.string().nullable().optional()}); export const lodgifyApiPublicReservationsModelsV2QuoteQuoteDto = z.object({total_including_vat: z.number().nullable().optional(), total_excluding_vat: z.number().nullable().optional(), total_vat: z.number().nullable().optional(), property_id: z.number().int().optional(), date_arrival: z.string().optional(), date_departure: z.string().optional(), currency_code: z.string().nullable().optional(), room_types: z.array(lodgifyApiPublicReservationsModelsV2QuoteQuoteRoomTypeDto).nullable().optional(), add_ons: z.array(lodgifyApiPublicReservationsModelsV2QuoteQuoteAddOnDto).nullable().optional(), other_items: z.array(lodgifyApiPublicReservationsModelsV2QuoteQuoteOtherItemDto).nullable().optional(), add_ons_subtotal: z.number().optional(), rate_policy_user_id: z.number().int().nullable().optional(), scheduled_payments: z.array(lodgifyApiPublicReservationsModelsV2QuoteQuoteScheduledTransactionDto).nullable().optional(), scheduled_damage_protection: z.array(lodgifyApiPublicReservationsModelsV2QuoteQuoteScheduledTransactionDto).nullable().optional(), security_deposit: z.number().optional(), total_scheduled_payments: z.number().optional(), total_to_collect_manually: z.number().optional(), amount_gross: z.number().optional(), rental_agreement: z.string().nullable().optional(), cancellation_policy_text: z.string().nullable().optional(), security_deposit_text: z.string().nullable().optional(), is_verification: z.boolean().optional()}); export const getApiV2QuotePropertyIdResponse = z.array(lodgifyApiPublicReservationsModelsV2QuoteQuoteDto); 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 }; /** * Gets a quote * * GET /v2/quote/{propertyId} */ export const getApiV2QuotePropertyId = async (args: GetApiV2QuotePropertyIdArgs, options?: GetApiV2QuotePropertyIdOptions) => { const {baseUrl = "https://api.lodgify.com", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.arrival != null) query.append("arrival", String(args.arrival)) if (args.departure != null) query.append("departure", String(args.departure)) for (const item of args.roomTypes ?? []) query.append("roomTypes", String(item)) for (const item of args.addOns ?? []) query.append("addOns", String(item)) if (args.promotionCode != null) query.append("promotionCode", String(args.promotionCode)) if (ApiKey !== undefined) headers.set("X-ApiKey", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v2/quote/${encodeURIComponent(String(args.propertyId))}${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(getApiV2QuotePropertyIdResponse, await res.json()) };