import {z} from 'zod' export type ListingIdParam = string; export type CurrencyISO = 'afn' | 'all' | 'dzd' | 'usd' | 'eur' | 'aoa' | 'xcd' | 'ars' | 'amd' | 'awg' | 'aud' | 'azn' | 'bsd' | 'bhd' | 'bdt' | 'bbd' | 'byn' | 'bzd' | 'xof' | 'bmd' | 'btn' | 'inr' | 'bob' | 'bov' | 'bam' | 'bwp' | 'nok' | 'brl' | 'bnd' | 'bgn' | 'bif' | 'cve' | 'khr' | 'xaf' | 'cad' | 'kyd' | 'clf' | 'clp' | 'cny' | 'cop' | 'cou' | 'kmf' | 'cdf' | 'nzd' | 'crc' | 'hrk' | 'cuc' | 'cup' | 'ang' | 'czk' | 'dkk' | 'djf' | 'dop' | 'egp' | 'svc' | 'ern' | 'etb' | 'fkp' | 'fjd' | 'xpf' | 'gmd' | 'gel' | 'ghs' | 'gip' | 'gtq' | 'gbp' | 'gnf' | 'gyd' | 'htg' | 'hnl' | 'hkd' | 'huf' | 'isk' | 'idr' | 'xdr' | 'irr' | 'iqd' | 'ils' | 'jmd' | 'jpy' | 'jod' | 'kzt' | 'kes' | 'kpw' | 'krw' | 'kwd' | 'kgs' | 'lak' | 'lbp' | 'lsl' | 'zar' | 'lrd' | 'lyd' | 'chf' | 'mop' | 'mga' | 'mwk' | 'myr' | 'mvr' | 'mru' | 'mur' | 'xua' | 'mxn' | 'mxv' | 'mdl' | 'mnt' | 'mad' | 'mzn' | 'mmk' | 'nad' | 'npr' | 'nio' | 'ngn' | 'omr' | 'pkr' | 'pab' | 'pgk' | 'pyg' | 'pen' | 'php' | 'pln' | 'qar' | 'mkd' | 'ron' | 'rub' | 'rwf' | 'shp' | 'wst' | 'stn' | 'sar' | 'rsd' | 'scr' | 'sle' | 'sgd' | 'xsu' | 'sbd' | 'sos' | 'ssp' | 'lkr' | 'sdg' | 'srd' | 'szl' | 'sek' | 'che' | 'chw' | 'syp' | 'twd' | 'tjs' | 'tzs' | 'thb' | 'top' | 'ttd' | 'tnd' | 'try' | 'tmt' | 'ugx' | 'uah' | 'aed' | 'usn' | 'uyi' | 'uyu' | 'uzs' | 'vuv' | 'vef' | 'ved' | 'vnd' | 'yer' | 'zmw' | 'zwl'; export type ListingFutureDailyPricingRequestSchema = {num_months: number, currency?: CurrencyISO | undefined}; export type CreateApiListingListingIdFuturePricingArgs = {listingId: ListingIdParam, body: ListingFutureDailyPricingRequestSchema}; export type CreateApiListingListingIdFuturePricingOptions = {baseUrl?: string | undefined, headerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const listingFutureDailyPricingResponseSchema = z.object({date: z.string(), status: z.union([z.literal(0), z.literal(1), z.literal(2)]), rate: z.number()}); export const status = z.object({type: z.enum(["success", "error"]), response_id: z.string(), message: z.string()}); export const createApiListingListingIdFuturePricingResponse = z.object({payload: z.object({pricing: z.array(listingFutureDailyPricingResponseSchema).optional()}), status: status}); 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 }; /** * Fetch Future Pricing for a Listing. * * POST /listing/{listingId}/future/pricing */ export const createApiListingListingIdFuturePricing = async (args: CreateApiListingListingIdFuturePricingArgs, options?: CreateApiListingListingIdFuturePricingOptions) => { const {baseUrl = "https://api.airdna.co/api/enterprise/v2", fetch: fetchFn = fetch, headerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (headerAuth !== undefined) headers.set('authorization', `Bearer ${headerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/listing/${encodeURIComponent(String(args.listingId))}/future/pricing${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(createApiListingListingIdFuturePricingResponse, await res.json()) };