import {z} from 'zod' export type UpdateApiV2InspectionReportsIdArgs = {id: number, 'X-Time-Zone'?: string | undefined, 'X-Metric-Units'?: boolean | undefined, time?: string | undefined, 'X-User-Id'?: number | undefined, body: {defect_statuses?: ({mechanic_signed_at?: string | undefined, resolver_id?: number | undefined, mechanic_name?: string | undefined, mechanic_note?: string | undefined, resolved_defects?: Array | undefined, status?: string | undefined, external_resolver_id?: string | undefined}) | undefined, external_ids_attributes?: ({external_id?: string | undefined, integration_name?: string | undefined}) | undefined}}; export type UpdateApiV2InspectionReportsIdOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiV2InspectionReportsIdResponse = z.object({inspection_report: z.object({id: z.number().int().optional(), log_id: z.number().int().optional(), date: z.string().optional(), time: z.string().optional(), odometer: z.unknown(), carrier_name: z.string().optional(), vehicle_number: z.string().optional(), trailer_nums: z.array(z.string()).optional(), location: z.string().optional(), city: z.string().optional(), state: z.string().optional(), status: z.string().optional(), mechanic_signed_at: z.string().optional(), mechanic_signature_url: z.string().optional(), driver_signed_at: z.string().optional(), driver_signature_url: z.string().optional(), reviewer_signed_at: z.string().optional(), reviewer_signature_url: z.string().optional(), defects: z.array(z.object({defect: z.object({id: z.number().int().optional(), area: z.string().optional(), category: z.string().optional(), notes: z.unknown()}).optional()})).optional(), vehicle: z.object({id: z.number().int().optional(), number: z.string().optional(), year: z.string().optional(), make: z.string().optional(), model: z.string().optional(), vin: z.string().optional(), metric_units: z.boolean().optional()}).optional(), mechanic: z.object({id: z.number().int().optional(), first_name: z.string().optional(), last_name: z.string().optional(), username: z.unknown(), email: z.string().optional(), driver_company_id: z.unknown(), status: z.string().optional(), role: z.string().optional()}).optional(), driver: z.object({id: z.number().int().optional(), first_name: z.string().optional(), last_name: z.string().optional(), username: z.string().optional(), email: z.unknown(), driver_company_id: z.unknown(), status: z.string().optional(), role: z.string().optional()}).optional(), reviewer: z.object({id: z.number().int().optional(), first_name: z.string().optional(), last_name: z.string().optional(), username: z.unknown(), email: z.string().optional(), driver_company_id: z.unknown(), status: z.string().optional(), role: z.string().optional()}).optional(), external_ids: z.array(z.object({external_id: z.string().optional(), integration_name: z.string().optional()})).optional(), entries: z.array(z.object({name: z.string().optional(), value: z.string().optional(), position: 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 }; /** * Update an existing inspection report (v2) * * PUT /v2/inspection_reports/{id} */ export const updateApiV2InspectionReportsId = async (args: UpdateApiV2InspectionReportsIdArgs, options?: UpdateApiV2InspectionReportsIdOptions) => { const {baseUrl = "https://api.gomotive.com", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-Time-Zone'] != null) headers.set("X-Time-Zone", String(args['X-Time-Zone'])) if (args['X-Metric-Units'] != null) headers.set("X-Metric-Units", String(args['X-Metric-Units'])) if (args.time != null) query.append("time", String(args.time)) if (args['X-User-Id'] != null) headers.set("X-User-Id", String(args['X-User-Id'])) if (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/v2/inspection_reports/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiV2InspectionReportsIdResponse, await res.json()) };