import {z} from 'zod' export type OverrideType = 'Active' | 'Inactive'; export type GetApiApiTenantsTenantIdPayrollsPayrollIdCasefieldsArgs = {tenantId: number, payrollId: number, caseFieldNames?: Array | undefined, clusterSetName?: string | undefined, evaluationDate?: string | undefined, overrideType?: OverrideType | undefined, regulationDate?: string | undefined}; export type GetApiApiTenantsTenantIdPayrollsPayrollIdCasefieldsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const objectStatus = z.enum(["Active", "Inactive"]); export const valueType = z.enum(["String", "Boolean", "Integer", "NumericBoolean", "Decimal", "DateTime", "None", "Date", "Weekday", "Month", "Year", "Money", "Percent", "WebResource"]); export const valueScope = z.enum(["Local", "Global"]); export const caseFieldTimeType = z.enum(["Timeless", "Moment", "Period", "CalendarPeriod"]); export const caseFieldTimeUnit = z.enum(["Day", "HalfDay", "Month"]); export const caseFieldAggregationType = z.enum(["Summary", "Last", "First"]); export const overrideType = z.enum(["Active", "Inactive"]); export const caseFieldCancellationMode = z.enum(["TimeType", "Previous", "Keep", "Reset", "Invert"]); export const caseValueCreationMode = z.enum(["OnChanges", "Always", "Discard"]); export const caseFieldDateType = z.enum(["Day", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Month", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "Year", "PeriodStart", "PeriodStartDate", "PeriodEnd", "PeriodEndDate", "CycleStart", "CycleStartDate", "CycleEnd", "CycleEndDate"]); export const lookupSettings = z.object({lookupName: z.string().min(1), valueFieldName: z.string().nullable().optional(), textFieldName: z.string().nullable().optional()}); export const caseField = z.object({id: z.number().int().optional(), status: objectStatus.optional(), created: z.string().optional(), updated: z.string().optional(), name: z.string().max(128), nameLocalizations: z.record(z.string(), z.string().nullable()).nullable().optional(), description: z.string().nullable().optional(), descriptionLocalizations: z.record(z.string(), z.string().nullable()).nullable().optional(), valueType: valueType.optional(), valueScope: valueScope.optional(), timeType: caseFieldTimeType.optional(), timeUnit: caseFieldTimeUnit.optional(), periodAggregation: caseFieldAggregationType.optional(), overrideType: overrideType.optional(), cancellationMode: caseFieldCancellationMode.optional(), valueCreationMode: caseValueCreationMode.optional(), culture: z.string().nullable().optional(), valueMandatory: z.boolean().optional(), order: z.number().int().optional(), startDateType: caseFieldDateType.optional(), endDateType: caseFieldDateType.optional(), endMandatory: z.boolean().optional(), defaultStart: z.string().nullable().optional(), defaultEnd: z.string().nullable().optional(), defaultValue: z.string().nullable().optional(), tags: z.array(z.string()).nullable().optional(), lookupSettings: lookupSettings.optional(), clusters: z.array(z.string()).nullable().optional(), attributes: z.record(z.string(), z.unknown()).nullable().optional(), valueAttributes: z.record(z.string(), z.unknown()).nullable().optional()}); export const getApiApiTenantsTenantIdPayrollsPayrollIdCasefieldsResponse = z.array(caseField); 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 /api/tenants/{tenantId}/payrolls/{payrollId}/casefields */ export const getApiApiTenantsTenantIdPayrollsPayrollIdCasefields = async (args: GetApiApiTenantsTenantIdPayrollsPayrollIdCasefieldsArgs, options: GetApiApiTenantsTenantIdPayrollsPayrollIdCasefieldsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.caseFieldNames ?? []) query.append("caseFieldNames", String(item)) if (args.clusterSetName != null) query.append("clusterSetName", String(args.clusterSetName)) if (args.evaluationDate != null) query.append("evaluationDate", String(args.evaluationDate)) if (args.overrideType != null) query.append("overrideType", String(args.overrideType)) if (args.regulationDate != null) query.append("regulationDate", String(args.regulationDate)) const url = `${baseUrl.replace(/\/+$/, '')}/api/tenants/${encodeURIComponent(String(args.tenantId))}/payrolls/${encodeURIComponent(String(args.payrollId))}/casefields${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(getApiApiTenantsTenantIdPayrollsPayrollIdCasefieldsResponse, await res.json()) };