import {z} from 'zod' export type GetApiV1SchedulingDriversArgs = {ActorId?: number | undefined, DriverStatusId?: number | undefined, Search?: string | undefined, SearchByDriverId?: boolean | undefined, SearchByUserId?: boolean | undefined, SearchByFullname?: boolean | undefined, SearchByMobile?: boolean | undefined, SearchByEmail?: boolean | undefined, SearchByIdNumber?: boolean | undefined, SearchByDriverLicense?: boolean | undefined}; export type GetApiV1SchedulingDriversOptions = {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 getApiV1SchedulingDriversResponse = z.array(driverResponseDto); 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 Drivers * * GET /v1/Scheduling/drivers */ export const getApiV1SchedulingDrivers = async (args: GetApiV1SchedulingDriversArgs, options?: GetApiV1SchedulingDriversOptions) => { const {baseUrl = "https://example.com:443", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.ActorId != null) query.append("ActorId", String(args.ActorId)) if (args.DriverStatusId != null) query.append("DriverStatusId", String(args.DriverStatusId)) if (args.Search != null) query.append("Search", String(args.Search)) if (args.SearchByDriverId != null) query.append("SearchByDriverId", String(args.SearchByDriverId)) if (args.SearchByUserId != null) query.append("SearchByUserId", String(args.SearchByUserId)) if (args.SearchByFullname != null) query.append("SearchByFullname", String(args.SearchByFullname)) if (args.SearchByMobile != null) query.append("SearchByMobile", String(args.SearchByMobile)) if (args.SearchByEmail != null) query.append("SearchByEmail", String(args.SearchByEmail)) if (args.SearchByIdNumber != null) query.append("SearchByIdNumber", String(args.SearchByIdNumber)) if (args.SearchByDriverLicense != null) query.append("SearchByDriverLicense", String(args.SearchByDriverLicense)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/Scheduling/drivers${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(getApiV1SchedulingDriversResponse, await res.json()) };