import {z} from 'zod' export type GetApiAnalyticsDashboardsProductSalesBreakdownRevenueBreakdownArgs = {TENANT: string, 'API-KEY': string, group_by?: ('location' | 'provider' | 'item_category' | 'payment_medium' | 'created_date' | null) | undefined, group_key?: (string | null) | undefined, timezone: string, sort_by?: string | undefined, sort_direction?: ('asc' | 'desc') | undefined, start_date?: (string | null) | undefined, end_date?: (string | null) | undefined, location_ids?: (Array | null) | undefined, location_names?: (Array | null) | undefined, provider_ids?: (Array | null) | undefined, provider_names?: (Array | null) | undefined, patient_ids?: (Array | null) | undefined, patient_names?: (Array | null) | undefined, item_categories?: (Array | null) | undefined, item_types?: (Array | null) | undefined, item_names?: (Array | null) | undefined, payment_mediums?: (Array | null) | undefined, min_net_amount?: (number | null) | undefined, max_net_amount?: (number | null) | undefined, comment?: (string | null) | undefined, item_category?: (string | null) | undefined, location?: (string | null) | undefined, provider?: (string | null) | undefined, payment_medium?: (string | null) | undefined, created_date?: (string | null) | undefined, page?: (number | null) | undefined, per_page?: (number | null) | undefined}; export type GetApiAnalyticsDashboardsProductSalesBreakdownRevenueBreakdownOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const providerTiny = z.object({id: z.string(), firstName: z.string(), lastName: z.string().nullable().optional(), email: z.string().nullable().optional(), createdDate: z.string().nullable().optional()}); export const userType = z.enum(["PROVIDER", "PATIENT", "ASSISTANT"]); export const patientTiny = z.object({id: z.string(), firstName: z.string().nullable().optional(), lastName: z.string().nullable().optional(), phoneNumber: z.string().nullable().optional(), email: z.string().nullable().optional(), type: userType.optional(), locationId: z.string().nullable().optional(), dateOfBirth: z.string().nullable().optional(), onSchedulingBlacklist: z.boolean().nullable().optional()}); export const revenueBreakdownItem = z.object({createdDate: z.string(), location: z.string().nullable().optional(), provider: providerTiny.nullable().optional(), patient: patientTiny, item: z.string(), itemType: z.string(), itemCategory: z.string(), quantity: z.number(), price: z.number().int(), grossAmount: z.number().int(), itemDiscountAmount: z.number().int(), chargeDiscountAmount: z.number().int(), taxAmount: z.number().int(), netAmount: z.number().int(), paymentMediums: z.array(z.string()).nullable().optional(), chargeId: z.string(), comment: z.string().nullable().optional()}); export const pageRevenueBreakdownItem = z.object({data: z.array(revenueBreakdownItem), 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 Revenue Breakdown * * GET /analytics/dashboards/product-sales-breakdown/revenue-breakdown */ export const getApiAnalyticsDashboardsProductSalesBreakdownRevenueBreakdown = async (args: GetApiAnalyticsDashboardsProductSalesBreakdownRevenueBreakdownArgs, options: GetApiAnalyticsDashboardsProductSalesBreakdownRevenueBreakdownOptions) => { 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.group_by != null) query.append("group_by", String(args.group_by)) if (args.group_key != null) query.append("group_key", String(args.group_key)) if (args.timezone != null) query.append("timezone", String(args.timezone)) 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.start_date != null) query.append("start_date", String(args.start_date)) if (args.end_date != null) query.append("end_date", String(args.end_date)) for (const item of args.location_ids ?? []) query.append("location_ids", String(item)) for (const item of args.location_names ?? []) query.append("location_names", String(item)) for (const item of args.provider_ids ?? []) query.append("provider_ids", String(item)) for (const item of args.provider_names ?? []) query.append("provider_names", String(item)) for (const item of args.patient_ids ?? []) query.append("patient_ids", String(item)) for (const item of args.patient_names ?? []) query.append("patient_names", String(item)) for (const item of args.item_categories ?? []) query.append("item_categories", String(item)) for (const item of args.item_types ?? []) query.append("item_types", String(item)) for (const item of args.item_names ?? []) query.append("item_names", String(item)) for (const item of args.payment_mediums ?? []) query.append("payment_mediums", String(item)) if (args.min_net_amount != null) query.append("min_net_amount", String(args.min_net_amount)) if (args.max_net_amount != null) query.append("max_net_amount", String(args.max_net_amount)) if (args.comment != null) query.append("comment", String(args.comment)) if (args.item_category != null) query.append("item_category", String(args.item_category)) if (args.location != null) query.append("location", String(args.location)) if (args.provider != null) query.append("provider", String(args.provider)) if (args.payment_medium != null) query.append("payment_medium", String(args.payment_medium)) if (args.created_date != null) query.append("created_date", String(args.created_date)) if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) const url = `${baseUrl.replace(/\/+$/, '')}/analytics/dashboards/product-sales-breakdown/revenue-breakdown${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(pageRevenueBreakdownItem, await res.json()) };