import {z} from 'zod' export type CountryCodeParam = 'ad' | 'ae' | 'af' | 'ag' | 'ai' | 'al' | 'am' | 'ao' | 'aq' | 'ar' | 'as' | 'at' | 'au' | 'aw' | 'ax' | 'az' | 'ba' | 'bb' | 'bd' | 'be' | 'bf' | 'bg' | 'bh' | 'bi' | 'bj' | 'bl' | 'bm' | 'bn' | 'bo' | 'bq' | 'br' | 'bs' | 'bt' | 'bv' | 'bw' | 'by' | 'bz' | 'ca' | 'cc' | 'cd' | 'cf' | 'cg' | 'ch' | 'ci' | 'ck' | 'cl' | 'cm' | 'cn' | 'co' | 'cr' | 'cu' | 'cv' | 'cw' | 'cx' | 'cy' | 'cz' | 'de' | 'dj' | 'dk' | 'dm' | 'do' | 'dz' | 'ec' | 'ee' | 'eg' | 'eh' | 'er' | 'es' | 'et' | 'fi' | 'fj' | 'fk' | 'fm' | 'fo' | 'fr' | 'ga' | 'gb' | 'gd' | 'ge' | 'gf' | 'gg' | 'gh' | 'gi' | 'gl' | 'gm' | 'gn' | 'gp' | 'gq' | 'gr' | 'gs' | 'gt' | 'gu' | 'gw' | 'gy' | 'hk' | 'hm' | 'hn' | 'hr' | 'ht' | 'hu' | 'id' | 'ie' | 'il' | 'im' | 'in' | 'io' | 'iq' | 'ir' | 'is' | 'it' | 'je' | 'jm' | 'jo' | 'jp' | 'ke' | 'kg' | 'kh' | 'ki' | 'km' | 'kn' | 'kp' | 'kr' | 'kw' | 'ky' | 'kz' | 'la' | 'lb' | 'lc' | 'li' | 'lk' | 'lr' | 'ls' | 'lt' | 'lu' | 'lv' | 'ly' | 'ma' | 'mc' | 'md' | 'me' | 'mf' | 'mg' | 'mh' | 'mk' | 'ml' | 'mm' | 'mn' | 'mo' | 'mp' | 'mq' | 'mr' | 'ms' | 'mt' | 'mu' | 'mv' | 'mw' | 'mx' | 'my' | 'mz' | 'na' | 'nc' | 'ne' | 'nf' | 'ng' | 'ni' | 'nl' | 'no' | 'np' | 'nr' | 'nu' | 'nz' | 'om' | 'pa' | 'pe' | 'pf' | 'pg' | 'ph' | 'pk' | 'pl' | 'pm' | 'pn' | 'pr' | 'ps' | 'pt' | 'pw' | 'py' | 'qa' | 're' | 'ro' | 'rs' | 'ru' | 'rw' | 'sa' | 'sb' | 'sc' | 'sd' | 'se' | 'sg' | 'sh' | 'si' | 'sj' | 'sk' | 'sl' | 'sm' | 'sn' | 'so' | 'sr' | 'ss' | 'st' | 'sv' | 'sx' | 'sy' | 'sz' | 'tc' | 'td' | 'tf' | 'tg' | 'th' | 'tj' | 'tk' | 'tl' | 'tm' | 'tn' | 'to' | 'tr' | 'tt' | 'tv' | 'tw' | 'tz' | 'ua' | 'ug' | 'um' | 'us' | 'uy' | 'uz' | 'va' | 'vc' | 've' | 'vg' | 'vi' | 'vn' | 'vu' | 'wf' | 'ws' | 'xk' | 'ye' | 'yt' | 'za' | 'zm' | 'zw'; export type PaginationRequestSchema = {offset: number, page_size: number}; export type GeomPoint = {lat: number, lng: number}; export type BoundingBoxRequestSchema = {ne?: GeomPoint | undefined, sw?: GeomPoint | undefined}; export type ChannelOption = 'airbnb' | 'vrbo' | 'booking'; export type ListingType = 'entire_place' | 'private_room' | 'shared_room'; export type MarketType = 'urban_metro' | 'mountains_lakes' | 'coastal' | 'suburban' | 'rural' | 'mid_size_city'; export type PriceTier = 'budget' | 'economy' | 'midscale' | 'upscale' | 'luxury'; export type RealEstateType = 'apartment' | 'bed_and_breakfast' | 'house' | 'unique'; export type CountryMarketsFilterListSchema = Array<{field: 'accommodates', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'accommodates', type: 'select', value: number} | {field: 'accommodates', type: 'range', value: Array} | {field: 'bathrooms', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'bathrooms', type: 'select', value: number} | {field: 'bathrooms', type: 'range', value: Array} | {field: 'bedrooms', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'bedrooms', type: 'select', value: number} | {field: 'bedrooms', type: 'range', value: Array} | {field: 'channels', type: 'jsonb_array', value: Array} | {field: 'channels', type: 'jsonb_array_subset', value: Array} | {field: 'channels', type: 'jsonb_array_exact', value: Array} | {field: 'investability', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'investability', type: 'select', value: number} | {field: 'investability', type: 'range', value: Array} | {field: 'listing_count', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'listing_count', type: 'select', value: number} | {field: 'listing_count', type: 'range', value: Array} | {field: 'listing_type', type: 'select', value: 'entire_place' | 'private_room' | 'shared_room'} | {field: 'listing_type', type: 'multi_select', value: Array} | {field: 'market_id', type: 'select', value: string} | {field: 'market_id', type: 'multi_select', value: Array} | {field: 'market_type', type: 'select', value: 'urban_metro' | 'mountains_lakes' | 'coastal' | 'suburban' | 'rural' | 'mid_size_city'} | {field: 'market_type', type: 'multi_select', value: Array} | {field: 'price_tier', type: 'select', value: 'budget' | 'economy' | 'midscale' | 'upscale' | 'luxury'} | {field: 'price_tier', type: 'multi_select', value: Array} | {field: 'professionally_managed', type: 'select', value: boolean} | {field: 'ratings', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'ratings', type: 'select', value: number} | {field: 'ratings', type: 'range', value: Array} | {field: 'real_estate_type', type: 'select', value: 'apartment' | 'bed_and_breakfast' | 'house' | 'unique'} | {field: 'real_estate_type', type: 'multi_select', value: Array} | {field: 'regulation', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'regulation', type: 'select', value: number} | {field: 'regulation', type: 'range', value: Array} | {field: 'rental_demand', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'rental_demand', type: 'select', value: number} | {field: 'rental_demand', type: 'range', value: Array} | {field: 'revenue_growth', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'revenue_growth', type: 'select', value: number} | {field: 'revenue_growth', type: 'range', value: Array} | {field: 'seasonality', type: 'gt' | 'gte' | 'lt' | 'lte', value: number} | {field: 'seasonality', type: 'select', value: number} | {field: 'seasonality', type: 'range', value: Array}>; 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 MarketSortOrder = 'market_score' | 'revenue' | 'occupancy' | 'adr' | 'review_count'; export type CountryMarketsRequestSchema = {pagination: PaginationRequestSchema, bounding_box?: BoundingBoxRequestSchema | undefined, filters?: CountryMarketsFilterListSchema | undefined, currency?: CurrencyISO | undefined, sort_order?: MarketSortOrder | undefined, include_geoms?: boolean | undefined}; export type CreateApiCountryCountryCodeMarketsArgs = {countryCode: CountryCodeParam, body: CountryMarketsRequestSchema}; export type CreateApiCountryCountryCodeMarketsOptions = {baseUrl?: string | undefined, headerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const paginationResponseSchema = z.object({total_count: z.number().gte(0), offset: z.number().gte(0), page_size: z.number().gte(1).lte(25)}); export const marketSortOrder = z.enum(["market_score", "revenue", "occupancy", "adr", "review_count"]); export const marketType = z.enum(["urban_metro", "mountains_lakes", "coastal", "suburban", "rural", "mid_size_city"]); export const marketMetrics = z.object({market_score: z.number().gte(0).lte(100), revenue: z.number(), booked: z.number().gte(0).lte(1), daily_rate: z.number(), revpar: z.number().nullable()}); export const geom = z.object({MultiPolygon: z.object({coordinates: z.array(z.array(z.object({LinearRing: z.array(z.object({Position: z.array(z.number()).optional()})).optional()})))}).optional()}); export const geomPoint = z.object({lat: z.number(), lng: z.number()}); export const geoSpatial = z.object({geom: geom.optional(), geom_pt: geomPoint.optional()}); export const market = z.object({id: z.string(), name: z.string(), market_type: marketType, images: z.array(z.string()), metrics: marketMetrics, geospatial: geoSpatial}); export const countryMarketsResponseSchema = z.object({page_info: paginationResponseSchema, sort_order: marketSortOrder, markets: z.array(market)}); export const status = z.object({type: z.enum(["success", "error"]), response_id: z.string(), message: z.string()}); export const createApiCountryCountryCodeMarketsResponse = z.object({payload: countryMarketsResponseSchema, 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 }; /** * Explore Markets within a Country. * * POST /country/{countryCode}/markets */ export const createApiCountryCountryCodeMarkets = async (args: CreateApiCountryCountryCodeMarketsArgs, options?: CreateApiCountryCountryCodeMarketsOptions) => { 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(/\/+$/, '')}/country/${encodeURIComponent(String(args.countryCode))}/markets${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(createApiCountryCountryCodeMarketsResponse, await res.json()) };