/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import * as openEnums from "../../types/enums.js"; import { OpenEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { CreditUsageReportPeriod, CreditUsageReportPeriod$inboundSchema, } from "./creditusagereportperiod.js"; import { SourceUsageBreakdown, SourceUsageBreakdown$inboundSchema, } from "./sourceusagebreakdown.js"; /** * The granularity of the report. */ export const Granularity = { Daily: "daily", Monthly: "monthly", } as const; /** * The granularity of the report. */ export type Granularity = OpenEnum; export type CreditUsageReport = { /** * The breakdown of credits consumed by consumer. This may not be present if the report is generated for a specific user. */ creditsConsumedByConsumer?: string | undefined; creditsConsumedBySource: SourceUsageBreakdown; /** * The end time of the window for this report. */ endTime: Date; /** * The granularity of the report. */ granularity: Granularity; /** * The periods of the report (i.e. time buckets). */ periods: Array | null; /** * The start time of the window for this report. */ startTime: Date; /** * The total amount of credits added during the report period. */ totalAdded: number; /** * The total amount of credits consumed during the report period. */ totalConsumed: number; /** * The total amount of credits expired during the report period. */ totalExpired: number; /** * The total number of transactions during the report period. */ transactionCount: number; }; /** @internal */ export const Granularity$inboundSchema: z.ZodType< Granularity, z.ZodTypeDef, unknown > = openEnums.inboundSchema(Granularity); /** @internal */ export const CreditUsageReport$inboundSchema: z.ZodType< CreditUsageReport, z.ZodTypeDef, unknown > = z.object({ credits_consumed_by_consumer: z.string().optional(), credits_consumed_by_source: SourceUsageBreakdown$inboundSchema, end_time: z.string().datetime({ offset: true }).transform(v => new Date(v)), granularity: Granularity$inboundSchema.default("daily"), periods: z.nullable(z.array(CreditUsageReportPeriod$inboundSchema)), start_time: z.string().datetime({ offset: true }).transform(v => new Date(v)), total_added: z.number().int(), total_consumed: z.number().int(), total_expired: z.number().int(), transaction_count: z.number().int(), }).transform((v) => { return remap$(v, { "credits_consumed_by_consumer": "creditsConsumedByConsumer", "credits_consumed_by_source": "creditsConsumedBySource", "end_time": "endTime", "start_time": "startTime", "total_added": "totalAdded", "total_consumed": "totalConsumed", "total_expired": "totalExpired", "transaction_count": "transactionCount", }); }); export function creditUsageReportFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CreditUsageReport$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreditUsageReport' from JSON`, ); }