import {z} from 'zod' export type GetApiApiV1SummaryGetPaymentStatsArgs = {branch_ids: string, start_time: string, end_time: string, label_type: string, payment_methods?: string | undefined}; export type GetApiApiV1SummaryGetPaymentStatsOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1SummaryGetPaymentStatsResponse = z.unknown(); 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 Payment Stats * * GET /api/v1/summary/get_payment_stats */ export const getApiApiV1SummaryGetPaymentStats = async (args: GetApiApiV1SummaryGetPaymentStatsArgs, options: GetApiApiV1SummaryGetPaymentStatsOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.branch_ids != null) query.append("branch_ids", String(args.branch_ids)) if (args.start_time != null) query.append("start_time", String(args.start_time)) if (args.end_time != null) query.append("end_time", String(args.end_time)) if (args.label_type != null) query.append("label_type", String(args.label_type)) if (args.payment_methods != null) query.append("payment_methods", String(args.payment_methods)) if (APIKeyHeader !== undefined) headers.set("secret-key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/summary/get_payment_stats${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(getApiApiV1SummaryGetPaymentStatsResponse, await res.json()) };