import {z} from 'zod' export type GetApiAnalyticsDashboardsProductSalesBreakdownRevenueBreakdownGroupSummariesArgs = {TENANT: string, 'API-KEY': string, group_by: 'location' | 'provider' | 'item_category' | 'payment_medium' | 'created_date', 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}; export type GetApiAnalyticsDashboardsProductSalesBreakdownRevenueBreakdownGroupSummariesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const decodaAppsApiRoutesAnalyticsDashboardsProductSalesBreakdownGroupSummary = z.object({groupKey: z.string(), totalItems: z.number().int(), totalQuantity: z.number().int(), totalGrossAmount: z.number().int(), totalItemDiscountAmount: z.number().int(), totalChargeDiscountAmount: z.number().int(), totalTaxAmount: z.number().int(), totalNetAmount: z.number().int(), uniquePatients: z.number().int(), uniqueProviders: z.number().int(), uniqueLocations: z.number().int()}); export const getApiAnalyticsDashboardsProductSalesBreakdownRevenueBreakdownGroupSummariesResponse = z.array(decodaAppsApiRoutesAnalyticsDashboardsProductSalesBreakdownGroupSummary); 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 Group Summaries * * GET /analytics/dashboards/product-sales-breakdown/revenue-breakdown-group-summaries */ export const getApiAnalyticsDashboardsProductSalesBreakdownRevenueBreakdownGroupSummaries = async (args: GetApiAnalyticsDashboardsProductSalesBreakdownRevenueBreakdownGroupSummariesArgs, options: GetApiAnalyticsDashboardsProductSalesBreakdownRevenueBreakdownGroupSummariesOptions) => { 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.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)) const url = `${baseUrl.replace(/\/+$/, '')}/analytics/dashboards/product-sales-breakdown/revenue-breakdown-group-summaries${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(getApiAnalyticsDashboardsProductSalesBreakdownRevenueBreakdownGroupSummariesResponse, await res.json()) };