import {z} from 'zod' export type EventUnit = 'day' | 'hour' | 'time'; export type GetApiScheduleApiWorkingTimeArrangementsArgs = {search?: string | undefined, isPartTime?: boolean | undefined, unit?: EventUnit | undefined, isArchived?: boolean | undefined, currentlyAssignedOnly?: boolean | undefined, sort?: ('id' | '-id') | undefined, page?: number | undefined, limit?: number | undefined, 'fields.root'?: 'count' | undefined}; export type GetApiScheduleApiWorkingTimeArrangementsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const eventUnit = z.enum(["day", "hour", "time"]); export const frequencyType = z.enum(["week", "year"]); export const dayOfWeek = z.enum(["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]); export const referenceWeek = z.object({frequencyType: frequencyType, firstDayOfWeek: dayOfWeek}); export const month = z.enum(["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"]); export const referenceYear = z.object({frequencyType: frequencyType, firstMonth: month}); export const duration = z.object({iso: z.string().optional(), unit: z.enum(["day", "hour"]).optional()}); export const fullDayAbsence = z.object({duration: duration, absenceAccountIds: z.array(z.number().int().gte(0)), absenceCategoryIds: z.array(z.number().int().gte(0))}); export const timesheetRegulation = z.object({id: z.number().int().gte(0), name: z.string().min(1)}); export const schedulePatternShape = z.enum(["singleWeek", "oddEvenWeeks"]); export const dayOffType = z.enum(["off", "partTime", "weeklyRest"]); export const dayPosition = z.enum(["firstHalf", "secondHalf", "fullDay"]); export const durationUnit = z.enum(["day", "hour"]); export const schedulePatternSummary = z.object({shape: schedulePatternShape, days: z.array(z.object({dayOffType: dayOffType.optional(), workPosition: dayPosition.optional(), workDuration: z.number().gte(0).nullable().optional(), workDurationUnit: durationUnit.optional()}))}); export const workingTimeArrangement = z.object({id: z.number().int().gte(0), name: z.string().min(3).max(1000), description: z.string().max(5000).nullable(), unit: eventUnit, referencePeriod: z.union([referenceWeek, referenceYear]).nullable().optional(), contractWorkingTimeDuration: duration.optional(), referenceWorkingTimeDuration: duration.optional(), fullTimeEquivalent: z.number().gte(0).lte(1).multipleOf(0.0001), fullDayAbsence: fullDayAbsence.optional(), publicHolidaysCalendar: z.object({id: z.number().int().gte(0), name: z.string().nullable().optional()}), isPartTime: z.boolean(), isArchived: z.boolean(), isScheduleValid: z.boolean(), currentAssignmentsCount: z.number().int().optional(), timesheetRegulation: timesheetRegulation.optional(), currentSchedulePatternSummary: schedulePatternSummary.optional(), authorizedCommands: z.array(z.enum(["create", "update", "delete", "archive", "unarchive"]))}); export const getApiScheduleApiWorkingTimeArrangementsResponse = z.object({items: z.array(workingTimeArrangement).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 }; /** * List Working Time Arrangements. * * GET /schedule/api/working-time-arrangements */ export const getApiScheduleApiWorkingTimeArrangements = async (args: GetApiScheduleApiWorkingTimeArrangementsArgs, options?: GetApiScheduleApiWorkingTimeArrangementsOptions) => { const {baseUrl = "https://example.ilucca.net", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.search != null) query.append("search", String(args.search)) if (args.isPartTime != null) query.append("isPartTime", String(args.isPartTime)) if (args.unit != null) query.append("unit", String(args.unit)) if (args.isArchived != null) query.append("isArchived", String(args.isArchived)) if (args.currentlyAssignedOnly != null) query.append("currentlyAssignedOnly", String(args.currentlyAssignedOnly)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args['fields.root'] != null) query.append("fields.root", String(args['fields.root'])) const url = `${baseUrl.replace(/\/+$/, '')}/schedule/api/working-time-arrangements${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(getApiScheduleApiWorkingTimeArrangementsResponse, await res.json()) };