import {z} from 'zod' export type MaintenanceScheduleInput = {name?: string | undefined, schedule_type: 'RRULE' | 'MANUAL' | 'ONE_OFF', starts_at: string, ends_at?: (string | null) | undefined, rrule?: string | undefined, duration_minutes?: (number | null) | undefined, is_active?: boolean | undefined, pause_checks_during_maintenance?: boolean | undefined, services?: Array | undefined, tags?: Array | undefined}; export type PatchApiApiV1MaintenanceSchedulesPkArgs = {pk: string, body: MaintenanceScheduleInput}; export type PatchApiApiV1MaintenanceSchedulesPkOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const maintenanceSchedule = z.object({id: z.number().int().optional(), name: z.string().optional(), schedule_type: z.enum(["RRULE", "MANUAL", "ONE_OFF"]).optional(), starts_at: z.string().optional(), ends_at: z.string().nullable().optional(), rrule: z.string().optional(), duration_minutes: z.number().int().nullable().optional(), is_active: z.boolean().optional(), pause_checks_during_maintenance: z.boolean().optional(), services: z.string().optional(), tags: z.array(z.object({id: z.number().int().optional(), tag: z.string().max(100), color_hex: z.string().optional(), usage_count: z.number().int().optional()})).optional(), created_at: z.string().optional(), modified_at: z.string().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 }; /** * Partially update a maintenance schedule * * PATCH /api/v1/maintenance/schedules/{pk}/ */ export const patchApiApiV1MaintenanceSchedulesPk = async (args: PatchApiApiV1MaintenanceSchedulesPkArgs, options: PatchApiApiV1MaintenanceSchedulesPkOptions) => { const {baseUrl, 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(/\/+$/, '')}/api/v1/maintenance/schedules/${encodeURIComponent(String(args.pk))}/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(maintenanceSchedule, await res.json()) };