import {z} from 'zod' export type GetApiWorkingpatternoverridecomponentsIdArgs = {id: string}; export type GetApiWorkingpatternoverridecomponentsIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const dayPart = z.enum(["AM", "PM", "AllDay", "None"]); export const workingPatternOverrideComponentModel = z.object({EmployeeId: z.string().max(36).nullable().optional(), StartDate: z.string().nullable().optional(), EndDate: z.string().nullable().optional(), DayOfWeek: z.number().int().optional(), DayOfWeekLabel: z.string().nullable().optional(), DurationDays: z.number().optional(), DurationMinutes: z.number().int().optional(), DayPart: dayPart.optional(), SourceSystemId: z.string().max(36).nullable().optional(), SourceSystemCreatedOn: z.string().nullable().optional(), SourceSystemLastModifiedOn: z.string().nullable().optional(), Id: z.string().nullable().optional(), CreatedOn: z.string().optional(), CreatedBy: z.string().nullable().optional(), LastModifiedOn: z.string().nullable().optional(), LastModifiedBy: 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 Working Pattern Override Component referenced by ID. * * GET /workingpatternoverridecomponents/{id} */ export const getApiWorkingpatternoverridecomponentsId = async (args: GetApiWorkingpatternoverridecomponentsIdArgs, options?: GetApiWorkingpatternoverridecomponentsIdOptions) => { 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 (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/workingpatternoverridecomponents/${encodeURIComponent(String(args.id))}${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(workingPatternOverrideComponentModel, await res.json()) };