import {z} from 'zod' export type DriverReportDatesFilteredBy = 'charge-transaction' | 'wallet-transaction'; export type GetApiApiV1InsightsChargesChargeAuthTokenReportArgs = {page?: number | undefined, perPage?: number | undefined, teamId: number, fromDate: string, toDate: string, datesFilteredBy?: (DriverReportDatesFilteredBy | null) | undefined}; export type GetApiApiV1InsightsChargesChargeAuthTokenReportOptions = {baseUrl?: string | undefined, BearerAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const chargesInsightByChargeAuthTokenReportDtoConsumption = z.object({chargeType: z.string(), totalSessions: z.number().int(), totalKwh: z.number(), totalNetPrice: z.number(), totalVat: z.number(), totalGrossPrice: z.number(), memberCostGroupId: z.number().int().nullable().optional(), memberCostGroupName: z.string().nullable().optional(), memberCostGroupPrice: z.number().nullable().optional()}); export const chargesInsightByChargeAuthTokenReportDto = z.object({id: z.number().int().optional(), identifier: z.string(), type: z.enum(["vehicleId", "rfid"]), consumptions: z.array(chargesInsightByChargeAuthTokenReportDtoConsumption)}); export const montaPageMeta = z.object({itemCount: z.number().int(), currentPage: z.number().int(), perPage: z.number().int(), totalPageCount: z.number().int(), totalItemCount: z.number().int()}); export const offsetBasedResponse28 = z.object({data: z.array(chargesInsightByChargeAuthTokenReportDto), meta: montaPageMeta}); 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 }; /** * Retrieve insights about charges broken down by charge auth token and member cost groups of a team. * * GET /api/v1/insights/charges/charge-auth-token-report */ export const getApiApiV1InsightsChargesChargeAuthTokenReport = async (args: GetApiApiV1InsightsChargesChargeAuthTokenReportArgs, options?: GetApiApiV1InsightsChargesChargeAuthTokenReportOptions) => { const {baseUrl = "https://partner-api.monta.com", fetch: fetchFn = fetch, BearerAccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.perPage != null) query.append("perPage", String(args.perPage)) if (args.teamId != null) query.append("teamId", String(args.teamId)) if (args.fromDate != null) query.append("fromDate", String(args.fromDate)) if (args.toDate != null) query.append("toDate", String(args.toDate)) if (args.datesFilteredBy != null) query.append("datesFilteredBy", String(args.datesFilteredBy)) if (BearerAccessToken !== undefined) headers.set('authorization', `Bearer ${BearerAccessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/insights/charges/charge-auth-token-report${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(offsetBasedResponse28, await res.json()) };