import {z} from 'zod' export type LineItemNoteAttachmentItemType = number; export type LineItemNoteAttachmentDto = {itemType?: LineItemNoteAttachmentItemType | undefined, itemId?: string | undefined}; export type LineItemNoteTemplateScope = number; export type SaveLineItemNoteTemplateRequest = {text?: string | undefined, title?: (string | null) | undefined, appliesToAnyItem?: boolean | undefined, attachments?: Array | undefined, scope?: LineItemNoteTemplateScope | undefined}; export type UpdateApiLineItemNotesIdArgs = {id: string, body: SaveLineItemNoteTemplateRequest}; export type UpdateApiLineItemNotesIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const lineItemNoteAttachmentItemType = z.number().int(); export const lineItemNoteAttachmentDto = z.object({itemType: lineItemNoteAttachmentItemType.optional(), itemId: z.string().optional()}); export const lineItemNoteTemplateScope = z.number().int(); export const lineItemNoteTemplateDto = z.object({id: z.string().optional(), text: z.string().optional(), title: z.string().nullable().optional(), appliesToAnyItem: z.boolean().optional(), attachments: z.array(lineItemNoteAttachmentDto).optional(), scope: lineItemNoteTemplateScope.optional(), createdByUserId: z.string().nullable().optional(), usageCount: z.union([z.number().int(), z.string()]).optional(), lastUsedAt: z.string().nullable().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 }; /** * Edit text/title/attachments/scope; the request's attachment list REPLACES the * existing set. Touching a Clinic template — or promoting a * Personal one to Clinic — requires the settings permission; a Personal template is * editable only by its owner (non-owners get 404 from the visibility filter). * * PUT /line-item-notes/{id} */ export const updateApiLineItemNotesId = async (args: UpdateApiLineItemNotesIdArgs, options?: UpdateApiLineItemNotesIdOptions) => { 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(/\/+$/, '')}/line-item-notes/${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(lineItemNoteTemplateDto, await res.json()) };