import {z} from 'zod' export type GetApiCalendarEmployeesEmployeeIdArgs = {employeeId: string, startDate: string, endDate: string, publicHolidays?: boolean | undefined, workingPatterns?: boolean | undefined, workingPatternOverrides?: boolean | undefined, absences?: boolean | undefined, ignoreShowOnCalendar?: boolean | undefined}; export type GetApiCalendarEmployeesEmployeeIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const dayPart = z.enum(["AM", "PM", "AllDay", "None"]); export const employeeCalendarDayAbsenceDay = z.object({Id: z.string().max(36).nullable().optional(), AbsenceId: z.string().nullable().optional(), AbsenceReasonId: z.string().max(36).nullable().optional(), AbsenceReasonParentName: z.string().max(50).nullable().optional(), EmployeeId: z.string().nullable().optional(), DurationDays: z.number().optional(), DurationMinutes: z.number().int().nullable().optional(), DayPart: dayPart.optional()}); export const employeeCalendarDay = z.object({Date: z.string().optional(), DurationDays: z.number().optional(), DurationMinutes: z.number().int().optional(), WorkingStartTime: z.string().nullable().optional(), WorkingEndTime: z.string().nullable().optional(), WorkingDayPart: dayPart.optional(), IsPublicHoliday: z.boolean().optional(), PublicHolidayDescription: z.string().max(50).nullable().optional(), PublicHolidayId: z.string().max(36).nullable().optional(), WorkingPatternId: z.string().max(36).nullable().optional(), WorkingPatternOverrideId: z.string().max(36).nullable().optional(), AbsenceDays: z.array(employeeCalendarDayAbsenceDay).nullable().optional()}); export const employeeCalendarModel = z.object({EmployeeId: z.string().max(36).nullable().optional(), StartDate: z.string().optional(), EndDate: z.string().optional(), SourceSystemId: z.string().max(36).nullable().optional(), SourceSystemCreatedOn: z.string().nullable().optional(), SourceSystemLastModifiedOn: z.string().nullable().optional(), Days: z.array(employeeCalendarDay).nullable().optional(), Id: z.string().max(36).nullable().optional(), CreatedOn: z.string().optional(), CreatedBy: z.string().max(36).nullable().optional(), LastModifiedOn: z.string().nullable().optional(), LastModifiedBy: z.string().max(36).nullable().optional(), Messages: z.array(z.string()).nullable().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 }; /** * Gets a single Employee Calendar referenced by Employee ID. * * GET /calendar/employees/{employeeId} */ export const getApiCalendarEmployeesEmployeeId = async (args: GetApiCalendarEmployeesEmployeeIdArgs, options?: GetApiCalendarEmployeesEmployeeIdOptions) => { const {baseUrl = "https://api.iris.co.uk/hr/v2", fetch: fetchFn = fetch, Bearer} = 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.publicHolidays != null) query.append("publicHolidays", String(args.publicHolidays)) if (args.workingPatterns != null) query.append("workingPatterns", String(args.workingPatterns)) if (args.workingPatternOverrides != null) query.append("workingPatternOverrides", String(args.workingPatternOverrides)) if (args.absences != null) query.append("absences", String(args.absences)) if (args.ignoreShowOnCalendar != null) query.append("ignoreShowOnCalendar", String(args.ignoreShowOnCalendar)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/calendar/employees/${encodeURIComponent(String(args.employeeId))}${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(employeeCalendarModel, await res.json()) };