import {z} from 'zod' export type ObjectStatus = 'Active' | 'Inactive'; export type OverrideType = 'Active' | 'Inactive'; export type CaseRelation = {id?: number | undefined, status?: ObjectStatus | undefined, created?: string | undefined, updated?: string | undefined, sourceCaseName: string, sourceCaseNameLocalizations?: ({[key: string]: string | null} | null) | undefined, sourceCaseSlot?: (string | null) | undefined, sourceCaseSlotLocalizations?: ({[key: string]: string | null} | null) | undefined, targetCaseName: string, targetCaseNameLocalizations?: ({[key: string]: string | null} | null) | undefined, targetCaseSlot?: (string | null) | undefined, targetCaseSlotLocalizations?: ({[key: string]: string | null} | null) | undefined, buildExpression?: (string | null) | undefined, validateExpression?: (string | null) | undefined, overrideType?: OverrideType | undefined, order?: number | undefined, buildActions?: (Array | null) | undefined, validateActions?: (Array | null) | undefined, attributes?: ({[key: string]: unknown} | null) | undefined, clusters?: (Array | null) | undefined}; export type CreateApiApiTenantsTenantIdRegulationsRegulationIdCaserelationsArgs = {tenantId: number, regulationId: number, body: CaseRelation}; export type CreateApiApiTenantsTenantIdRegulationsRegulationIdCaserelationsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const objectStatus = z.enum(["Active", "Inactive"]); export const overrideType = z.enum(["Active", "Inactive"]); export const caseRelation = z.object({id: z.number().int().optional(), status: objectStatus.optional(), created: z.string().optional(), updated: z.string().optional(), sourceCaseName: z.string().max(128), sourceCaseNameLocalizations: z.record(z.string(), z.string().nullable()).nullable().optional(), sourceCaseSlot: z.string().max(128).nullable().optional(), sourceCaseSlotLocalizations: z.record(z.string(), z.string().nullable()).nullable().optional(), targetCaseName: z.string().max(128), targetCaseNameLocalizations: z.record(z.string(), z.string().nullable()).nullable().optional(), targetCaseSlot: z.string().max(128).nullable().optional(), targetCaseSlotLocalizations: z.record(z.string(), z.string().nullable()).nullable().optional(), buildExpression: z.string().nullable().optional(), validateExpression: z.string().nullable().optional(), overrideType: overrideType.optional(), order: z.number().int().optional(), buildActions: z.array(z.string()).nullable().optional(), validateActions: z.array(z.string()).nullable().optional(), attributes: z.record(z.string(), z.unknown()).nullable().optional(), clusters: z.array(z.string()).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}/caserelations */ export const createApiApiTenantsTenantIdRegulationsRegulationIdCaserelations = async (args: CreateApiApiTenantsTenantIdRegulationsRegulationIdCaserelationsArgs, options: CreateApiApiTenantsTenantIdRegulationsRegulationIdCaserelationsOptions) => { 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))}/caserelations${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(caseRelation, await res.json()) };