import {z} from 'zod' export type GetApiV2ProvidersLeavePoliciesYearsofservicebasedleaveYearsOfServiceBasedLeaveIdArgs = {yearsOfServiceBasedLeaveId: string, Authorization: string, Accept: string, filter?: string | undefined, orderBy?: string | undefined, pageNumber?: number | undefined, pageSize?: number | undefined}; export type GetApiV2ProvidersLeavePoliciesYearsofservicebasedleaveYearsOfServiceBasedLeaveIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const version = z.object({obsoleteDate: z.string().nullable().optional(), resourceVersion: z.string().optional()}); export const messageWarning = z.array(z.object({type: z.string().optional(), description: z.string().optional(), id: z.string().nullable().optional(), code: z.number().int().optional(), properties: z.array(z.string()).optional()})); export const id = z.string(); export const yearsOfServiceBasedLeave = z.object({id: id.optional(), from: z.object({numberOfYears: z.number().int().gte(0).lte(999).optional(), numberOfMonths: z.number().int().gte(0).lte(11).optional()}).optional(), upToAndIncluding: z.object({numberOfYears: z.number().int().gte(0).lte(999).optional(), numberOfMonths: z.number().int().gte(0).lte(11).optional()}).optional(), leaveEntitlement: z.object({excessLeaveToStatutory: z.number().gte(0.01).lte(999.99).nullable().optional(), wtr: z.number().gte(0.01).lte(999.99).nullable().optional()}).optional()}); export const getApiV2ProvidersLeavePoliciesYearsofservicebasedleaveYearsOfServiceBasedLeaveIdResponse = z.object({version: version.optional(), messages: messageWarning.optional(), content: yearsOfServiceBasedLeave.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 }; /** * A years of service based leave record * * GET /v2/providers/leavePolicies/yearsofservicebasedleave/{yearsOfServiceBasedLeaveId} */ export const getApiV2ProvidersLeavePoliciesYearsofservicebasedleaveYearsOfServiceBasedLeaveId = async (args: GetApiV2ProvidersLeavePoliciesYearsofservicebasedleaveYearsOfServiceBasedLeaveIdArgs, options?: GetApiV2ProvidersLeavePoliciesYearsofservicebasedleaveYearsOfServiceBasedLeaveIdOptions) => { const {baseUrl = "https://api.loket.nl", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json;version=2018-01-01") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (args.filter != null) query.append("filter", String(args.filter)) if (args.orderBy != null) query.append("orderBy", String(args.orderBy)) if (args.pageNumber != null) query.append("pageNumber", String(args.pageNumber)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) const url = `${baseUrl.replace(/\/+$/, '')}/v2/providers/leavePolicies/yearsofservicebasedleave/${encodeURIComponent(String(args.yearsOfServiceBasedLeaveId))}${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(getApiV2ProvidersLeavePoliciesYearsofservicebasedleaveYearsOfServiceBasedLeaveIdResponse, await res.json()) };