import {z} from 'zod' export type GetApiEmployeesIdBenefitsArgs = {id: string, $top?: number | undefined, $skip?: number | undefined, $filter?: string | undefined, $select?: Array | undefined, $orderby?: string | undefined, $count?: boolean | undefined}; export type GetApiEmployeesIdBenefitsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const valueWithCurrency = z.object({Value: z.number().nullable().optional(), CurrencyCode: z.string().max(50).nullable().optional(), CurrencySymbol: z.string().max(3).nullable().optional()}); export const benefitModel = z.object({EmployeeId: z.string().min(1).max(36), Type: z.string().max(50).nullable().optional(), Description: z.string().max(4805).nullable().optional(), Value: z.number().nullable().optional(), ValueWithCurrency: valueWithCurrency.optional(), StartDate: z.string().nullable().optional(), EndDate: z.string().nullable().optional(), P11DValue: z.number().nullable().optional(), P11DValueWithCurrency: valueWithCurrency.optional(), Suspended: z.boolean().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 benefitQueryModel = z.object({"@odata.context": z.string().nullable().optional(), "@odata.count": z.number().int().nullable().optional(), "@odata.nextlink": z.string().nullable().optional(), value: z.array(benefitModel).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 an Employee's Benefits. * * GET /employees/{id}/benefits */ export const getApiEmployeesIdBenefits = async (args: GetApiEmployeesIdBenefitsArgs, options?: GetApiEmployeesIdBenefitsOptions) => { 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(/\/+$/, '')}/employees/${encodeURIComponent(String(args.id))}/benefits${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(benefitQueryModel, await res.json()) };