import {z} from 'zod' export type GetApiBusinessBusinessIdLodgingArgs = {business_id: string}; export type GetApiBusinessBusinessIdLodgingOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const lodgingExceptionCode = z.enum(["LODGING_EXCEPTION_UNSPECIFIED", "LODGING_UNDER_CONSTRUCTION", "LODGING_DEPENDENT_ON_DAY_OF_WEEK", "LODGING_DEPENDENT_ON_SEASON"]); export const lodgingAttributeValueBOOL = z.object({gmb_id: z.string(), type: z.literal("BOOL"), value: z.boolean().nullable().optional(), exception: lodgingExceptionCode.nullable().optional()}); export const lodgingAttributeValueINTEGER = z.object({gmb_id: z.string(), type: z.literal("INTEGER"), value: z.number().int().nullable().optional(), exception: lodgingExceptionCode.nullable().optional()}); export const lodgingAttributeValueTIME = z.object({gmb_id: z.string(), type: z.literal("TIME"), value: z.string().nullable().optional(), exception: lodgingExceptionCode.nullable().optional()}); export const lodgingAttributeValueENUM = z.object({gmb_id: z.string(), type: z.literal("ENUM"), value: z.string().nullable().optional(), exception: lodgingExceptionCode.nullable().optional()}); export const lodgingAttributeValueREPEATABLEENUM = z.object({gmb_id: z.string(), type: z.literal("REPEATABLE_ENUM"), value: z.array(z.string()).nullable().optional(), exception: lodgingExceptionCode.nullable().optional()}); export const lodgingAttributeValue = z.discriminatedUnion("type", [lodgingAttributeValueBOOL, lodgingAttributeValueINTEGER, lodgingAttributeValueTIME, lodgingAttributeValueENUM, lodgingAttributeValueREPEATABLEENUM]); export const lodgingAttributeValueArray = z.array(lodgingAttributeValue); export const businessLodgingResponse = z.object({lodging: lodgingAttributeValueArray.nullable()}); 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 }; /** * Google Lodging attributes for your business * * GET /business/{business_id}/lodging */ export const getApiBusinessBusinessIdLodging = async (args: GetApiBusinessBusinessIdLodgingArgs, options?: GetApiBusinessBusinessIdLodgingOptions) => { const {baseUrl = "https://api.partoo.co/v2", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("x-APIKey", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/business/${encodeURIComponent(String(args.business_id))}/lodging${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(businessLodgingResponse, await res.json()) };