import {z} from 'zod' export type GetApiV1PropertiesIdRatesAddonsArgs = {id: number, start?: string | undefined, end?: string | undefined, rid?: number | undefined}; export type GetApiV1PropertiesIdRatesAddonsOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const lodgifyApiPropertiesModelsV1CurrencyDto = z.object({id: z.number().int().optional(), code: z.string().nullable().optional(), name: z.string().nullable().optional(), euro_forex: z.number().optional(), symbol: z.string().nullable().optional()}); export const lodgifyApiPropertiesModelsV1PropertyAddOnDto = z.object({id: z.number().int().optional(), name: z.string().nullable().optional(), description: z.string().nullable().optional(), charge_type: z.string().nullable().optional(), rate_type: z.string().nullable().optional(), max_quantity: z.number().int().nullable().optional(), frequency: z.string().nullable().optional(), percentage: z.number().nullable().optional(), amount: z.number().nullable().optional(), original_amount: z.number().nullable().optional(), image_url: z.string().nullable().optional(), currency: lodgifyApiPropertiesModelsV1CurrencyDto.optional()}); export const getApiV1PropertiesIdRatesAddonsResponse = z.array(lodgifyApiPropertiesModelsV1PropertyAddOnDto); 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 }; /** * Available addons * * GET /v1/properties/{id}/rates/addons */ export const getApiV1PropertiesIdRatesAddons = async (args: GetApiV1PropertiesIdRatesAddonsArgs, options?: GetApiV1PropertiesIdRatesAddonsOptions) => { 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.start != null) query.append("start", String(args.start)) if (args.end != null) query.append("end", String(args.end)) if (args.rid != null) query.append("rid", String(args.rid)) if (ApiKey !== undefined) headers.set("X-ApiKey", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/properties/${encodeURIComponent(String(args.id))}/rates/addons${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(getApiV1PropertiesIdRatesAddonsResponse, await res.json()) };