import {z} from 'zod' export type GetApiLAdminDcAllBookingsArgs = {booking_status: string, user_location: string, search_start_date?: string | undefined, search_end_date?: string | undefined, search_created_date?: string | undefined, car_managed_by?: number | undefined, search_key?: string | undefined, remaining_amount_status?: string | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiLAdminDcAllBookingsOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiLAdminDcAllBookingsResponse = z.unknown(); 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 }; /** * Get Bookings By Status * * GET /l-admin-dc/all-bookings */ export const getApiLAdminDcAllBookings = async (args: GetApiLAdminDcAllBookingsArgs, options?: GetApiLAdminDcAllBookingsOptions) => { const {baseUrl = "https://api.longdrivecars.com", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.booking_status != null) query.append("booking_status", String(args.booking_status)) if (args.user_location != null) query.append("user_location", String(args.user_location)) if (args.search_start_date != null) query.append("search_start_date", String(args.search_start_date)) if (args.search_end_date != null) query.append("search_end_date", String(args.search_end_date)) if (args.search_created_date != null) query.append("search_created_date", String(args.search_created_date)) if (args.car_managed_by != null) query.append("car_managed_by", String(args.car_managed_by)) if (args.search_key != null) query.append("search_key", String(args.search_key)) if (args.remaining_amount_status != null) query.append("remaining_amount_status", String(args.remaining_amount_status)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/l-admin-dc/all-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(getApiLAdminDcAllBookingsResponse, await res.json()) };