import {z} from 'zod' export type DriverWorkingHours = {StartHour?: (string | null) | undefined, EndHour?: (string | null) | undefined}; export type DriverWorkingDayAndHours = {Day?: number | undefined, Enabled?: boolean | undefined, Hours?: (Array | null) | undefined}; export type DriverRequestDto = {UserId?: number | undefined, OperatorId?: number | undefined, DriverStatusId?: (number | null) | undefined, StartDate?: (string | null) | undefined, DriverLicense?: (string | null) | undefined, IdNumber?: (string | null) | undefined, Skills?: (Array | null) | undefined, WorkingHours?: (Array | null) | undefined}; export type UpdateApiV1SchedulingDriversArgs = {DriverId?: string | undefined, body: DriverRequestDto}; export type UpdateApiV1SchedulingDriversOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const driverResponseDto = z.object({Id: z.string().optional(), DistributorId: z.number().int().optional(), OperatorId: z.number().int().optional(), OperatorName: z.string().nullable().optional(), UserId: z.number().int().optional(), FullName: z.string().nullable().optional(), Mobile: z.string().nullable().optional(), Email: z.string().nullable().optional(), DriverLicense: z.string().nullable().optional(), IdNumber: z.string().nullable().optional(), Img: z.string().nullable().optional(), DriverStatusId: z.number().int().nullable().optional(), StartDate: z.string().nullable().optional(), Skills: z.array(z.number().int()).nullable().optional(), WorkingHours: z.string().nullable().optional(), CreatedBy: z.number().int().optional(), CreatedDt: z.string().optional(), UpdatedBy: z.number().int().nullable().optional(), UpdatedDt: z.string().nullable().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 Driver * * PUT /v1/Scheduling/drivers */ export const updateApiV1SchedulingDrivers = async (args: UpdateApiV1SchedulingDriversArgs, options?: UpdateApiV1SchedulingDriversOptions) => { const {baseUrl = "https://example.com:443", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.DriverId != null) query.append("DriverId", String(args.DriverId)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/Scheduling/drivers${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(driverResponseDto, await res.json()) };