import {z} from 'zod' export type GetApiWorkingpatterncomponentsIdArgs = {id: string}; export type GetApiWorkingpatterncomponentsIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const dayPart = z.enum(["AM", "PM", "AllDay", "None"]); export const workingPatternComponentsDay = z.object({DayId: z.number().int().optional(), SourceSystemId: z.number().int().nullable().optional(), Description: z.string().max(50).nullable().optional(), DurationDays: z.number().optional(), DurationMinutes: z.number().int().optional(), WorkingStartTime: z.string().optional(), WorkingEndTime: z.string().optional(), WorkingDayPart: dayPart.optional()}); export const workingPatternComponentsPeriodSequence = z.object({Sequence: z.number().int().optional(), DayId: z.number().int().optional()}); export const workingPatternComponentsPeriod = z.object({StartDate: z.string().optional(), StartOnDayOfSequence: z.number().int().optional(), FixedDayOfWeek: z.boolean().optional(), Sequence: z.array(workingPatternComponentsPeriodSequence).nullable().optional(), InUse: z.boolean().optional(), SourceSystemId: z.number().int().nullable().optional()}); export const workingPatternComponentsModel = z.object({Description: z.string().max(50).nullable().optional(), Days: z.array(workingPatternComponentsDay).nullable().optional(), Periods: z.array(workingPatternComponentsPeriod).nullable().optional(), SourceSystemId: z.string().max(50).nullable().optional(), SourceSystemCreatedOn: z.string().nullable().optional(), SourceSystemLastModifiedOn: z.string().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()}); 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 }; /** * Get a Working Pattern Components by Id. * * GET /workingpatterncomponents/{id} */ export const getApiWorkingpatterncomponentsId = async (args: GetApiWorkingpatterncomponentsIdArgs, options?: GetApiWorkingpatterncomponentsIdOptions) => { 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(/\/+$/, '')}/workingpatterncomponents/${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(workingPatternComponentsModel, await res.json()) };