import {z} from 'zod' 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 RentalizerEstimateRequestAddressSchema = {address: string, bedrooms?: (number | null) | undefined, bathrooms?: (number | null) | undefined, accommodates?: (number | null) | undefined, currency?: CurrencyISO | undefined}; export type RentalizerEstimateRequestLatLngSchema = {lat: number, lng: number, bedrooms?: (number | null) | undefined, bathrooms?: (number | null) | undefined, accommodates?: (number | null) | undefined, currency?: CurrencyISO | undefined}; export type CreateApiRentalizerBulkSummaryArgs = {body: {queries: Array}}; export type CreateApiRentalizerBulkSummaryOptions = {baseUrl?: string | undefined, headerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const rentalizerPropertyDetails = z.object({address: z.string().nullable(), address_lookup: z.string().nullable(), zipcode: z.string().nullable(), accommodates: z.number().int(), bedrooms: z.number().int(), bathrooms: z.number()}); export const geomPoint = z.object({lat: z.number(), lng: z.number()}); export const rentalizerSummaryResult = z.object({details: rentalizerPropertyDetails, location: geomPoint, stats: z.object({currency: z.string(), currency_symbol: z.string(), property_value: z.number().nullable(), future: z.object({summary: z.object({adr: z.number(), occupancy: z.number(), revenue: z.number()}).optional()})})}); export const currencyISO = z.enum(["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 const rentalizerBulkSummaryResponseSchema = z.object({results: z.array(rentalizerSummaryResult), failed: z.array(z.union([z.object({address: z.string(), bedrooms: z.number().int().nullable().optional(), bathrooms: z.number().nullable().optional(), accommodates: z.number().int().nullable().optional(), currency: currencyISO.optional()}), z.object({lat: z.number(), lng: z.number(), bedrooms: z.number().int().nullable().optional(), bathrooms: z.number().nullable().optional(), accommodates: z.number().int().nullable().optional(), currency: currencyISO.optional()})]))}); export const status = z.object({type: z.enum(["success", "error"]), response_id: z.string(), message: z.string()}); export const createApiRentalizerBulkSummaryResponse = z.object({payload: rentalizerBulkSummaryResponseSchema, 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 }; /** * Bulk: Request Summarized Performance Estimates for Multiple Addresses or Locations. * * POST /rentalizer/bulk_summary */ export const createApiRentalizerBulkSummary = async (args: CreateApiRentalizerBulkSummaryArgs, options?: CreateApiRentalizerBulkSummaryOptions) => { 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(/\/+$/, '')}/rentalizer/bulk_summary${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(createApiRentalizerBulkSummaryResponse, await res.json()) };