import {z} from 'zod' export type ObjectStatus = 'Active' | 'Inactive'; export type ValueType = 'String' | 'Boolean' | 'Integer' | 'NumericBoolean' | 'Decimal' | 'DateTime' | 'None' | 'Date' | 'Weekday' | 'Month' | 'Year' | 'Money' | 'Percent' | 'WebResource'; export type CaseRelationReference = {sourceCaseName?: (string | null) | undefined, sourceCaseSlot?: (string | null) | undefined, targetCaseName?: (string | null) | undefined, targetCaseSlot?: (string | null) | undefined}; export type CaseDocument = {id?: number | undefined, status?: ObjectStatus | undefined, created?: string | undefined, updated?: string | undefined, name: string, content: string, contentType: string}; export type CaseValueSetup = {id?: number | undefined, status?: ObjectStatus | undefined, created?: string | undefined, updated?: string | undefined, divisionId?: (number | null) | undefined, employeeId?: (number | null) | undefined, caseName?: (string | null) | undefined, caseNameLocalizations?: ({[key: string]: string | null} | null) | undefined, caseFieldName: string, caseFieldNameLocalizations?: ({[key: string]: string | null} | null) | undefined, caseSlot?: (string | null) | undefined, caseSlotLocalizations?: ({[key: string]: string | null} | null) | undefined, valueType?: ValueType | undefined, value?: (string | null) | undefined, numericValue?: (number | null) | undefined, culture?: (string | null) | undefined, caseRelation?: CaseRelationReference | undefined, cancellationDate?: (string | null) | undefined, start?: (string | null) | undefined, end?: (string | null) | undefined, forecast?: (string | null) | undefined, tags?: (Array | null) | undefined, attributes?: ({[key: string]: unknown} | null) | undefined, documents?: (Array | null) | undefined}; export type CaseSetup = {id?: number | undefined, status?: ObjectStatus | undefined, created?: string | undefined, updated?: string | undefined, caseName: string, caseSlot?: (string | null) | undefined, values?: (Array | null) | undefined, relatedCases?: (Array | null) | undefined}; export type CaseIssueType = 'Unknown' | 'CaseInvalid' | 'CaseUnknown' | 'CaseRelationInvalid' | 'CaseFieldDuplicated' | 'CaseValueIncomplete' | 'CaseValueMissing' | 'CaseValueStartInvalid' | 'CaseValueEndInvalid' | 'CaseValueEndMissing' | 'CaseValueWeekdayInvalid' | 'CaseValueMonthInvalid'; export type CaseValidationIssue = {issueType: CaseIssueType, number?: number | undefined, caseName: string, caseNameLocalizations?: ({[key: string]: string | null} | null) | undefined, caseSlot?: (string | null) | undefined, caseSlotLocalizations?: ({[key: string]: string | null} | null) | undefined, caseFieldName?: (string | null) | undefined, caseFieldNameLocalizations?: ({[key: string]: string | null} | null) | undefined, sourceCaseName?: (string | null) | undefined, sourceCaseNameLocalizations?: ({[key: string]: string | null} | null) | undefined, sourceCaseSlot?: (string | null) | undefined, sourceCaseSlotLocalizations?: ({[key: string]: string | null} | null) | undefined, targetCaseName?: (string | null) | undefined, targetCaseNameLocalizations?: ({[key: string]: string | null} | null) | undefined, targetCaseSlot?: (string | null) | undefined, targetCaseSlotLocalizations?: ({[key: string]: string | null} | null) | undefined, message: string}; export type CaseChangeSetup = {userId: number, employeeId?: (number | null) | undefined, divisionId?: (number | null) | undefined, cancellationId?: (number | null) | undefined, forecast?: (string | null) | undefined, created?: (string | null) | undefined, reason?: (string | null) | undefined, case: CaseSetup, issues?: (Array | null) | undefined}; export type CreateApiApiTenantsTenantIdPayrollsPayrollIdCasesArgs = {tenantId: number, payrollId: number, body: CaseChangeSetup}; export type CreateApiApiTenantsTenantIdPayrollsPayrollIdCasesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const objectStatus = z.enum(["Active", "Inactive"]); export const caseCancellationType = z.enum(["None", "Case"]); export const valueType = z.enum(["String", "Boolean", "Integer", "NumericBoolean", "Decimal", "DateTime", "None", "Date", "Weekday", "Month", "Year", "Money", "Percent", "WebResource"]); export const caseRelationReference = z.object({sourceCaseName: z.string().nullable().optional(), sourceCaseSlot: z.string().nullable().optional(), targetCaseName: z.string().nullable().optional(), targetCaseSlot: z.string().nullable().optional()}); export const caseValue = z.object({id: z.number().int().optional(), status: objectStatus.optional(), created: z.string().optional(), updated: z.string().optional(), divisionId: z.number().int().nullable().optional(), employeeId: z.number().int().nullable().optional(), caseName: z.string().max(128).nullable().optional(), caseNameLocalizations: z.record(z.string(), z.string().nullable()).nullable().optional(), caseFieldName: z.string().max(128), caseFieldNameLocalizations: z.record(z.string(), z.string().nullable()).nullable().optional(), caseSlot: z.string().max(128).nullable().optional(), caseSlotLocalizations: z.record(z.string(), z.string().nullable()).nullable().optional(), valueType: valueType.optional(), value: z.string().nullable().optional(), numericValue: z.number().nullable().optional(), culture: z.string().nullable().optional(), caseRelation: caseRelationReference.optional(), cancellationDate: z.string().nullable().optional(), start: z.string().nullable().optional(), end: z.string().nullable().optional(), forecast: z.string().max(128).nullable().optional(), tags: z.array(z.string()).nullable().optional(), attributes: z.record(z.string(), z.unknown()).nullable().optional()}); export const caseChange = z.object({id: z.number().int().optional(), status: objectStatus.optional(), created: z.string().optional(), updated: z.string().optional(), userId: z.number().int(), employeeId: z.number().int().nullable().optional(), divisionId: z.number().int().nullable().optional(), cancellationType: caseCancellationType.optional(), cancellationId: z.number().int().nullable().optional(), cancellationDate: z.string().nullable().optional(), reason: z.string().nullable().optional(), validationCaseName: z.string().nullable().optional(), forecast: z.string().nullable().optional(), values: z.array(caseValue).nullable().optional(), ignoredValues: z.array(caseValue).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 }; /** * POST /api/tenants/{tenantId}/payrolls/{payrollId}/cases */ export const createApiApiTenantsTenantIdPayrollsPayrollIdCases = async (args: CreateApiApiTenantsTenantIdPayrollsPayrollIdCasesArgs, options: CreateApiApiTenantsTenantIdPayrollsPayrollIdCasesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/tenants/${encodeURIComponent(String(args.tenantId))}/payrolls/${encodeURIComponent(String(args.payrollId))}/cases${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(caseChange, await res.json()) };