/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 * @generated-id: 08465ac4ba80
 */

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export type UsageInfo = {
  promptTokens?: number | undefined;
  completionTokens?: number | undefined;
  totalTokens?: number | undefined;
  promptAudioSeconds?: number | null | undefined;
  [additionalProperties: string]: unknown;
};

/** @internal */
export const UsageInfo$inboundSchema: z.ZodType<UsageInfo, unknown> = z.object({
  prompt_tokens: z.int().default(0),
  completion_tokens: z.int().default(0),
  total_tokens: z.int().default(0),
  prompt_audio_seconds: z.nullable(z.int()).optional(),
}).catchall(z.any()).transform((v) => {
  return remap$(v, {
    "prompt_tokens": "promptTokens",
    "completion_tokens": "completionTokens",
    "total_tokens": "totalTokens",
    "prompt_audio_seconds": "promptAudioSeconds",
  });
});
/** @internal */
export type UsageInfo$Outbound = {
  prompt_tokens: number;
  completion_tokens: number;
  total_tokens: number;
  prompt_audio_seconds?: number | null | undefined;
  [additionalProperties: string]: unknown;
};

/** @internal */
export const UsageInfo$outboundSchema: z.ZodType<
  UsageInfo$Outbound,
  UsageInfo
> = z.object({
  promptTokens: z.int().default(0),
  completionTokens: z.int().default(0),
  totalTokens: z.int().default(0),
  promptAudioSeconds: z.nullable(z.int()).optional(),
}).catchall(z.any()).transform((v) => {
  return {
    ...remap$(v, {
      promptTokens: "prompt_tokens",
      completionTokens: "completion_tokens",
      totalTokens: "total_tokens",
      promptAudioSeconds: "prompt_audio_seconds",
    }),
  };
});

export function usageInfoToJSON(usageInfo: UsageInfo): string {
  return JSON.stringify(UsageInfo$outboundSchema.parse(usageInfo));
}
export function usageInfoFromJSON(
  jsonString: string,
): SafeParseResult<UsageInfo, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => UsageInfo$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'UsageInfo' from JSON`,
  );
}
