import {z} from 'zod' export type GetApiSearchParentBookingsArgs = {offset?: number | undefined, limit?: number | undefined, search?: string | undefined, order_by?: string | undefined, created_gt?: string | undefined, created_lt?: string | undefined, location_ids?: string | undefined, purpose?: string | undefined, deleted?: boolean | undefined}; export type GetApiSearchParentBookingsOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const searchParentBookingsMeta = z.object({limit: z.number().int().optional(), offset: z.number().int().optional(), total: z.number().int().optional()}); export const searchParentBookingItem = z.object({bookings_count: z.number().int().optional(), created: z.string().optional(), display_status: z.string().optional(), id: z.number().int().optional(), name: z.string().optional(), notes: z.string().optional(), purpose: z.string().optional(), status: z.string().optional()}); export const searchParentBookingsResponse = z.object({meta: searchParentBookingsMeta.optional(), parent_bookings: z.array(searchParentBookingItem).optional()}); 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 }; /** * Search Parent Bookings * * GET /search/parent-bookings * * Also accepts auth: API-Key */ export const getApiSearchParentBookings = async (args: GetApiSearchParentBookingsArgs, options: GetApiSearchParentBookingsOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.search != null) query.append("search", String(args.search)) if (args.order_by != null) query.append("order_by", String(args.order_by)) if (args.created_gt != null) query.append("created_gt", String(args.created_gt)) if (args.created_lt != null) query.append("created_lt", String(args.created_lt)) if (args.location_ids != null) query.append("location_ids", String(args.location_ids)) if (args.purpose != null) query.append("purpose", String(args.purpose)) if (args.deleted != null) query.append("deleted", String(args.deleted)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/search/parent-bookings${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(searchParentBookingsResponse, await res.json()) };