import {z} from 'zod' export type CreateWorkItemRuleItemMapRequest = {billableItemId?: (string | null) | undefined, vaccineTypeId?: (string | null) | undefined, serviceCatalogItemId?: (string | null) | undefined, inventoryItemId?: (string | null) | undefined}; export type UpdateWorkItemRuleRequest = {name?: (string | null) | undefined, description?: (string | null) | undefined, titleTemplate?: (string | null) | undefined, descriptionTemplate?: (string | null) | undefined, speciesIds?: (Array | null) | undefined, requiredTagIds?: (Array | null) | undefined, excludedTagIds?: (Array | null) | undefined, triggerTagId?: (string | null) | undefined, minAgeMonths?: (number | unknown | null) | undefined, maxAgeMonths?: (number | unknown | null) | undefined, cadenceOffsetsDays?: (Array | null) | undefined, recurrenceIntervalMonths?: (number | unknown | null) | undefined, autoSatisfyOnTrigger?: (boolean | null) | undefined, isActive?: (boolean | null) | undefined, locationId?: (string | null) | undefined, emitReminderCategory?: (string | null) | undefined, emitTaskCategory?: (string | null) | undefined, emitTaskPriority?: (string | null) | undefined, triggerEventTypes?: (Array | null) | undefined, itemMaps?: (Array | null) | undefined}; export type UpdateApiApiWorkItemRulesIdArgs = {id: string, body: UpdateWorkItemRuleRequest}; export type UpdateApiApiWorkItemRulesIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const workItemRuleKind = z.number().int(); export const workItemType = z.number().int(); export const reminderCategory = z.number().int(); export const workTaskCategory = z.number().int(); export const priority = z.number().int(); export const workItemRuleItemMapDto = z.object({id: z.string().optional(), billableItemId: z.string().nullable().optional(), billableItemName: z.string().nullable().optional(), vaccineTypeId: z.string().nullable().optional(), vaccineTypeName: z.string().nullable().optional(), serviceCatalogItemId: z.string().nullable().optional(), serviceCatalogItemName: z.string().nullable().optional(), inventoryItemId: z.string().nullable().optional(), inventoryItemName: z.string().nullable().optional()}); export const workItemRuleDto = z.object({id: z.string().optional(), name: z.string().optional(), description: z.string().nullable().optional(), kind: workItemRuleKind.optional(), emitType: workItemType.optional(), emitReminderCategory: reminderCategory.nullable().optional(), emitTaskCategory: workTaskCategory.nullable().optional(), emitTaskPriority: priority.nullable().optional(), titleTemplate: z.string().nullable().optional(), descriptionTemplate: z.string().nullable().optional(), triggerEventTypes: z.array(z.string()).optional(), speciesIds: z.array(z.string()).nullable().optional(), requiredTagIds: z.array(z.string()).nullable().optional(), excludedTagIds: z.array(z.string()).nullable().optional(), triggerTagId: z.string().nullable().optional(), minAgeMonths: z.union([z.number().int(), z.string()]).nullable().optional(), maxAgeMonths: z.union([z.number().int(), z.string()]).nullable().optional(), locationId: z.string().nullable().optional(), cadenceOffsetsDays: z.array(z.union([z.number().int(), z.string()])).optional(), recurrenceIntervalMonths: z.union([z.number().int(), z.string()]).nullable().optional(), autoSatisfyOnTrigger: z.boolean().optional(), isActive: z.boolean().optional(), version: z.union([z.number().int(), z.string()]).optional(), itemMaps: z.array(workItemRuleItemMapDto).optional(), createdAt: z.string().optional(), updatedAt: z.string().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 }; /** * PUT /api/work-item-rules/{id} */ export const updateApiApiWorkItemRulesId = async (args: UpdateApiApiWorkItemRulesIdArgs, options?: UpdateApiApiWorkItemRulesIdOptions) => { const {baseUrl = "https://api.clinicos.vet/backend/business", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/work-item-rules/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(workItemRuleDto, await res.json()) };