import {z} from 'zod' export type GetApiAttendanceAdoptionsArgs = {$top?: number | undefined, $skip?: number | undefined, $filter?: string | undefined, $select?: Array | undefined, $orderby?: string | undefined, $count?: boolean | undefined}; export type GetApiAttendanceAdoptionsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const adoptionModel = z.object({FormReceivedDate: z.string().nullable().optional(), ExpectedDateOfBirth: z.string().nullable().optional(), ExpectedWeekOfChildBirthStartDate: z.string().nullable().optional(), ExpectedWeekOfChildBirthEndDate: z.string().nullable().optional(), ChildDateOfBirth: z.string().nullable().optional(), ChildName: z.string().max(50).nullable().optional(), NotificationReceivedDate: z.string().nullable().optional(), NotifyEmployerByDate: z.string().nullable().optional(), LeaveStartDate: z.string().nullable().optional(), LeaveEndDate: z.string().nullable().optional(), Narrative: z.string().nullable().optional(), EmployeeId: z.string().nullable().optional(), AbsenceId: z.string().nullable().optional(), IntentionToReturnSentDate: z.string().nullable().optional(), ReturnToWorkIntention: z.string().nullable().optional(), ExpectedReturnDate: z.string().nullable().optional(), QualifyingWeekStartDate: z.string().nullable().optional(), QualifyForExtendLeave: z.boolean().nullable().optional(), IsSurrogacyCase: z.boolean().optional(), PlacementDate: z.string().nullable().optional(), SourceSystemId: z.string().max(36).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 adoptionQueryModel = z.object({"@odata.context": z.string().nullable().optional(), "@odata.count": z.number().int().nullable().optional(), "@odata.nextlink": z.string().nullable().optional(), value: z.array(z.array(adoptionModel)).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 list of Adoptions. * * GET /attendance/adoptions */ export const getApiAttendanceAdoptions = async (args: GetApiAttendanceAdoptionsArgs, options?: GetApiAttendanceAdoptionsOptions) => { 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.$top != null) query.append("$top", String(args.$top)) if (args.$skip != null) query.append("$skip", String(args.$skip)) if (args.$filter != null) query.append("$filter", String(args.$filter)) if (args.$select != null) query.append("$select", args.$select.join(',')) if (args.$orderby != null) query.append("$orderby", String(args.$orderby)) if (args.$count != null) query.append("$count", String(args.$count)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/attendance/adoptions${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(adoptionQueryModel, await res.json()) };