import {z} from 'zod' export type ReminderCategory = number; export type ReminderStatus = number; export type GetApiRemindersArgs = {PatientId?: string | undefined, ClientId?: string | undefined, IncludePatients?: boolean | undefined, AppointmentId?: string | undefined, Category?: ReminderCategory | undefined, Status?: ReminderStatus | undefined, IsActive?: boolean | undefined, IsCompleted?: boolean | undefined, DueDateFrom?: string | undefined, DueDateTo?: string | undefined, SortBy?: string | undefined, SortOrder?: string | undefined, Page?: (number | unknown) | undefined, PageSize?: (number | unknown) | undefined}; export type GetApiRemindersOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const reminderCategory = z.number().int(); export const reminderOrigin = z.number().int(); export const emissionSource = z.number().int(); export const reminderCompletionType = z.number().int(); export const reminderStatus = z.number().int(); export const reminderResponseDto = z.object({id: z.string().optional(), title: z.string().optional(), description: z.string().nullable().optional(), category: reminderCategory.optional(), origin: reminderOrigin.optional(), dueDate: z.string().optional(), snoozeUntil: z.string().nullable().optional(), isActive: z.boolean().optional(), isCompleted: z.boolean().optional(), completedAt: z.string().nullable().optional(), patientId: z.string().nullable().optional(), patientName: z.string().nullable().optional(), clientId: z.string().nullable().optional(), clientName: z.string().nullable().optional(), appointmentId: z.string().nullable().optional(), customAttributes: z.object({}).nullable().optional(), emissionSource: emissionSource.optional(), generatedByRuleId: z.string().nullable().optional(), generatedByRuleVersion: z.union([z.number().int(), z.string()]).nullable().optional(), triggerEventType: z.string().nullable().optional(), triggerEntityType: z.string().nullable().optional(), triggerEntityId: z.string().nullable().optional(), suppressedAt: z.string().nullable().optional(), suppressedByUserId: z.string().nullable().optional(), suppressedReason: z.string().nullable().optional(), completionType: reminderCompletionType.nullable().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), status: reminderStatus.optional()}); export const reminderListResponse = z.object({data: z.array(reminderResponseDto).optional(), totalCount: z.union([z.number().int(), z.string()]).optional(), page: z.union([z.number().int(), z.string()]).optional(), pageSize: z.union([z.number().int(), z.string()]).optional(), totalPages: z.union([z.number().int(), 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 }; /** * Get reminders with filtering and pagination * * GET /Reminders */ export const getApiReminders = async (args: GetApiRemindersArgs, options?: GetApiRemindersOptions) => { const {baseUrl = "https://api.clinicos.vet/backend/business", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.PatientId != null) query.append("PatientId", String(args.PatientId)) if (args.ClientId != null) query.append("ClientId", String(args.ClientId)) if (args.IncludePatients != null) query.append("IncludePatients", String(args.IncludePatients)) if (args.AppointmentId != null) query.append("AppointmentId", String(args.AppointmentId)) if (args.Category != null) query.append("Category", String(args.Category)) if (args.Status != null) query.append("Status", String(args.Status)) if (args.IsActive != null) query.append("IsActive", String(args.IsActive)) if (args.IsCompleted != null) query.append("IsCompleted", String(args.IsCompleted)) if (args.DueDateFrom != null) query.append("DueDateFrom", String(args.DueDateFrom)) if (args.DueDateTo != null) query.append("DueDateTo", String(args.DueDateTo)) if (args.SortBy != null) query.append("SortBy", String(args.SortBy)) if (args.SortOrder != null) query.append("SortOrder", String(args.SortOrder)) if (args.Page != null) query.append("Page", String(args.Page)) if (args.PageSize != null) query.append("PageSize", String(args.PageSize)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/Reminders${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(reminderListResponse, await res.json()) };