import {z} from 'zod' export type UpdateApiV1LogSuggestionsIdArgs = {id: number, body: {vehicle_ids?: ({''?: Array | undefined}) | undefined, asset_ids?: ({''?: Array | undefined}) | undefined, co_driver_ids?: ({''?: Array | undefined}) | undefined, ref_no?: string | undefined, carrier_name?: string | undefined, carrier_street?: string | undefined, carrier_zip?: string | undefined, terminal_street?: string | undefined, terminal_city?: string | undefined, terminal_state?: string | undefined, terminal_zip?: string | undefined, origin?: string | undefined, destination?: string | undefined}}; export type UpdateApiV1LogSuggestionsIdOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiV1LogSuggestionsIdResponse = z.object({log_suggestion: z.object({id: z.number().int().optional(), driver_ids: z.array(z.number().int()).optional(), log_ids: z.array(z.number().int()).optional(), status: z.string().optional(), suggested_at: z.string().optional(), reason: z.unknown(), drivers: z.array(z.object({driver: z.object({id: z.number().int().optional(), first_name: z.string().optional(), last_name: z.string().optional(), driver_company_id: z.string().optional(), eld_mode: z.string().optional()}).optional()})).optional(), dispatchers: z.array(z.object({dispatcher: z.object({id: z.number().int().optional(), first_name: z.string().optional(), last_name: z.string().optional()}).optional()})).optional(), suggested_changes: z.array(z.object({field_name: z.string().optional(), old_value: z.unknown(), new_value: z.string().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 log suggestion using an ID * * PUT /v1/log_suggestions/{id} */ export const updateApiV1LogSuggestionsId = async (args: UpdateApiV1LogSuggestionsIdArgs, options?: UpdateApiV1LogSuggestionsIdOptions) => { 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 (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/v1/log_suggestions/${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(updateApiV1LogSuggestionsIdResponse, await res.json()) };