import {z} from 'zod' export type EventIcon = 'BOOKING_FEE_PAID' | 'NEW_PATIENT' | 'SCHEDULED_BY_AI' | 'FORM_COMPLETED' | 'CHECKED_IN'; export type GetApiUserEventIconsListArgs = {TENANT: string, 'API-KEY': string, page?: (number | null) | undefined, per_page?: (number | null) | undefined, sort_by?: (string | null) | undefined, sort_direction?: ('asc' | 'desc' | null) | undefined, location_id?: (string | null) | undefined, icon_type?: (EventIcon | null) | undefined, is_active?: (boolean | null) | undefined}; export type GetApiUserEventIconsListOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const eventIcon = z.enum(["BOOKING_FEE_PAID", "NEW_PATIENT", "SCHEDULED_BY_AI", "FORM_COMPLETED", "CHECKED_IN"]); export const eventIconSummary = z.object({id: z.string(), iconType: eventIcon, emoji: z.string(), color: z.string(), isActive: z.boolean(), createdDate: z.string(), updatedDate: z.string().nullable().optional()}); export const pageEventIconSummary = z.object({data: z.array(eventIconSummary), total: z.number().int()}); 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 Event Icons * * GET /user/event-icons/list */ export const getApiUserEventIconsList = async (args: GetApiUserEventIconsListArgs, options: GetApiUserEventIconsListOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.TENANT != null) headers.set("TENANT", String(args.TENANT)) if (args['API-KEY'] != null) headers.set("API-KEY", String(args['API-KEY'])) if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.sort_by != null) query.append("sort_by", String(args.sort_by)) if (args.sort_direction != null) query.append("sort_direction", String(args.sort_direction)) if (args.location_id != null) query.append("location_id", String(args.location_id)) if (args.icon_type != null) query.append("icon_type", String(args.icon_type)) if (args.is_active != null) query.append("is_active", String(args.is_active)) const url = `${baseUrl.replace(/\/+$/, '')}/user/event-icons/list${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(pageEventIconSummary, await res.json()) };