import {z} from 'zod' export type RepeatOn = {Tasks?: (string | null) | undefined, Days?: (string | null) | undefined, Week?: (string | null) | undefined, MonthDay?: (string | null) | undefined, SetPos?: (string | null) | undefined, RecurrenceEx?: (string | null) | undefined, WeekNumber?: (string | null) | undefined}; export type Pattern = {PatternId?: (number | null) | undefined, Name?: (string | null) | undefined, Description?: (string | null) | undefined, RepeatType?: (number | null) | undefined, RepeatInterval?: number | undefined, IsStatic?: boolean | undefined, StartOn?: (string | null) | undefined, EndOn?: (string | null) | undefined, EndAfter?: (number | null) | undefined, RepeatOn?: (Array | null) | undefined}; export type TaskSchedulingCreateDto = {MachineId?: number | undefined, TaskLutId?: (string | null) | undefined, DriverId?: (string | null) | undefined, ScheduleDate?: (string | null) | undefined, StatusId?: number | undefined, Notes?: (string | null) | undefined, GeneratePickList?: boolean | undefined, GeneratePickListTime?: (string | null) | undefined, GeneratePickListRange?: (number | null) | undefined, ScheduleNextWorkingDay?: boolean | undefined, TimezoneOffset?: number | undefined, AssignedToPatternId?: (number | null) | undefined, AssignedToScheduleId?: (number | null) | undefined, Pattern?: Pattern | undefined, IsMobile?: (boolean | null) | undefined, IsSeriesUpdate?: (boolean | null) | undefined, OriginalDate?: (string | null) | undefined, IncompletionReasonId?: (number | null) | undefined, IncompletionReason?: (string | null) | undefined}; export type CreateApiV1SchedulingScheduleMachineTasksArgs = {body: Array}; export type CreateApiV1SchedulingScheduleMachineTasksOptions = {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 createApiV1SchedulingScheduleMachineTasksResponse = z.array(scheduleTaskDto); 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 }; /** * Create Machine Tasks * * POST /v1/Scheduling/schedule/machine-tasks */ export const createApiV1SchedulingScheduleMachineTasks = async (args: CreateApiV1SchedulingScheduleMachineTasksArgs, options?: CreateApiV1SchedulingScheduleMachineTasksOptions) => { 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") const url = `${baseUrl.replace(/\/+$/, '')}/v1/Scheduling/schedule/machine-tasks${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiV1SchedulingScheduleMachineTasksResponse, await res.json()) };