import {z} from 'zod' export type GetApiV1SchedulingScheduleMachineTasksArgs = {StartDate?: string | undefined, EndDate?: string | undefined, SchedulingId?: number | undefined, ActorId?: number | undefined, MachineId?: number | undefined, DriverId?: string | undefined, RouteId?: number | undefined, TimePeriod?: number | undefined, IsForlist?: boolean | undefined, IsStatic?: boolean | undefined}; export type GetApiV1SchedulingScheduleMachineTasksOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const entityPicture = z.object({EntityPictureId: z.number().int().optional(), EntityPictureUrl: z.string().nullable().optional()}); export const repeatOn = z.object({Tasks: z.string().nullable().optional(), Days: z.string().nullable().optional(), Week: z.string().nullable().optional(), MonthDay: z.string().nullable().optional(), SetPos: z.string().nullable().optional(), RecurrenceEx: z.string().nullable().optional(), WeekNumber: z.string().nullable().optional()}); export const pattern = z.object({PatternId: z.number().int().nullable().optional(), Name: z.string().nullable().optional(), Description: z.string().nullable().optional(), RepeatType: z.number().int().nullable().optional(), RepeatInterval: z.number().int().optional(), IsStatic: z.boolean().optional(), StartOn: z.string().nullable().optional(), EndOn: z.string().nullable().optional(), EndAfter: z.number().int().nullable().optional(), RepeatOn: z.array(repeatOn).nullable().optional()}); export const scheduleTaskDto = z.object({MachineId: z.number().int().optional(), TaskLutId: z.string().nullable().optional(), SchedulingId: z.number().int().optional(), DriverId: z.string().nullable().optional(), DriverName: z.string().nullable().optional(), TimezoneOffset: z.number().optional(), ScheduleDate: z.string().nullable().optional(), StatusId: z.number().int().optional(), Notes: z.string().nullable().optional(), GeneratePickList: z.boolean().optional(), GeneratePickListTime: z.string().nullable().optional(), GeneratePickListRange: z.number().int().nullable().optional(), ScheduleNextWorkingDay: z.boolean().optional(), AssignedToPatternId: z.number().int().nullable().optional(), AssignedToScheduleId: z.number().int().nullable().optional(), IncompletionReason: z.string().nullable().optional(), IncompletionReasonImages: z.array(entityPicture).nullable().optional(), Pattern: pattern.optional(), IsClustered: z.boolean().nullable().optional(), ClusterIds: z.string().nullable().optional(), CreatedBy: z.number().int().optional(), CreatedDt: z.string().optional(), UpdatedBy: z.number().int().nullable().optional(), UpdatedDt: z.string().nullable().optional(), isMobile: z.boolean().nullable().optional(), isSeriesUpdate: z.boolean().nullable().optional(), originalDate: z.string().nullable().optional(), IncompletionReasonId: z.number().int().nullable().optional(), IncompletionReasonName: z.string().nullable().optional()}); export const taskSchedulingResponseDto = z.object({MachineId: z.number().int().optional(), RouteId: z.number().int().nullable().optional(), RouteName: z.string().nullable().optional(), VisitDate: z.string().nullable().optional(), ScheduleTasks: z.array(scheduleTaskDto).nullable().optional()}); export const getApiV1SchedulingScheduleMachineTasksResponse = z.array(taskSchedulingResponseDto); 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 Machine Tasks * * GET /v1/Scheduling/schedule/machine-tasks */ export const getApiV1SchedulingScheduleMachineTasks = async (args: GetApiV1SchedulingScheduleMachineTasksArgs, options?: GetApiV1SchedulingScheduleMachineTasksOptions) => { 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.StartDate != null) query.append("StartDate", String(args.StartDate)) if (args.EndDate != null) query.append("EndDate", String(args.EndDate)) if (args.SchedulingId != null) query.append("SchedulingId", String(args.SchedulingId)) if (args.ActorId != null) query.append("ActorId", String(args.ActorId)) if (args.MachineId != null) query.append("MachineId", String(args.MachineId)) if (args.DriverId != null) query.append("DriverId", String(args.DriverId)) if (args.RouteId != null) query.append("RouteId", String(args.RouteId)) if (args.TimePeriod != null) query.append("TimePeriod", String(args.TimePeriod)) if (args.IsForlist != null) query.append("IsForlist", String(args.IsForlist)) if (args.IsStatic != null) query.append("IsStatic", String(args.IsStatic)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/Scheduling/schedule/machine-tasks${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(getApiV1SchedulingScheduleMachineTasksResponse, await res.json()) };