import {z} from 'zod' export type GetApiV1VideoRecallRequestsVehiclesAvailableTimelinesArgs = {vehicle_number?: string | undefined}; export type GetApiV1VideoRecallRequestsVehiclesAvailableTimelinesOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1VideoRecallRequestsVehiclesAvailableTimelinesResponse = z.object({vehicle: z.object({id: z.number().int().optional(), number: z.string().optional()}).optional(), primary_entity: z.string().optional(), eld_device: z.object({id: z.number().int().optional(), identifier: z.string().optional()}).optional(), available_timelines: z.array(z.object({end_time: z.string().optional(), start_time: z.string().optional()})).optional(), quota_info: z.object({regular: z.object({used_minutes: z.number().int().optional(), remaining_minutes: z.number().int().optional(), total_minutes: z.number().int().optional()}).optional(), timelapse: z.object({used_minutes: z.number().int().optional(), remaining_minutes: z.number().int().optional(), total_minutes: z.number().int().optional()}).optional()}).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 }; /** * Fetch the available timelines for a vehicle * * GET /v1/video_recall_requests/vehicles/available_timelines */ export const getApiV1VideoRecallRequestsVehiclesAvailableTimelines = async (args: GetApiV1VideoRecallRequestsVehiclesAvailableTimelinesArgs, options?: GetApiV1VideoRecallRequestsVehiclesAvailableTimelinesOptions) => { const {baseUrl = "https://api.gomotive.com", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.vehicle_number != null) query.append("vehicle_number", String(args.vehicle_number)) if (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/v1/video_recall_requests/vehicles/available_timelines${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(getApiV1VideoRecallRequestsVehiclesAvailableTimelinesResponse, await res.json()) };