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 ValueScope = 'Local' | 'Global'; export type CaseFieldTimeType = 'Timeless' | 'Moment' | 'Period' | 'CalendarPeriod'; export type CaseFieldTimeUnit = 'Day' | 'HalfDay' | 'Month'; export type CaseFieldAggregationType = 'Summary' | 'Last' | 'First'; export type OverrideType = 'Active' | 'Inactive'; export type CaseFieldCancellationMode = 'TimeType' | 'Previous' | 'Keep' | 'Reset' | 'Invert'; export type CaseValueCreationMode = 'OnChanges' | 'Always' | 'Discard'; export type CaseFieldDateType = '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 type LookupSettings = {lookupName: string, valueFieldName?: (string | null) | undefined, textFieldName?: (string | null) | undefined}; export type CaseField = {id?: number | undefined, status?: ObjectStatus | undefined, created?: string | undefined, updated?: string | undefined, name: string, nameLocalizations?: ({[key: string]: string | null} | null) | undefined, description?: (string | null) | undefined, descriptionLocalizations?: ({[key: string]: string | null} | null) | undefined, valueType?: ValueType | undefined, valueScope?: ValueScope | undefined, timeType?: CaseFieldTimeType | undefined, timeUnit?: CaseFieldTimeUnit | undefined, periodAggregation?: CaseFieldAggregationType | undefined, overrideType?: OverrideType | undefined, cancellationMode?: CaseFieldCancellationMode | undefined, valueCreationMode?: CaseValueCreationMode | undefined, culture?: (string | null) | undefined, valueMandatory?: boolean | undefined, order?: number | undefined, startDateType?: CaseFieldDateType | undefined, endDateType?: CaseFieldDateType | undefined, endMandatory?: boolean | undefined, defaultStart?: (string | null) | undefined, defaultEnd?: (string | null) | undefined, defaultValue?: (string | null) | undefined, tags?: (Array | null) | undefined, lookupSettings?: LookupSettings | undefined, clusters?: (Array | null) | undefined, attributes?: ({[key: string]: unknown} | null) | undefined, valueAttributes?: ({[key: string]: unknown} | null) | undefined}; export type CreateApiApiTenantsTenantIdRegulationsRegulationIdCasesCaseIdFieldsArgs = {tenantId: number, caseId: number, regulationId: string, body: CaseField}; export type CreateApiApiTenantsTenantIdRegulationsRegulationIdCasesCaseIdFieldsOptions = {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 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}/regulations/{regulationId}/cases/{caseId}/fields */ export const createApiApiTenantsTenantIdRegulationsRegulationIdCasesCaseIdFields = async (args: CreateApiApiTenantsTenantIdRegulationsRegulationIdCasesCaseIdFieldsArgs, options: CreateApiApiTenantsTenantIdRegulationsRegulationIdCasesCaseIdFieldsOptions) => { 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))}/regulations/${encodeURIComponent(String(args.regulationId))}/cases/${encodeURIComponent(String(args.caseId))}/fields${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(caseField, await res.json()) };