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

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";
import {
  CompletionTokensDetails,
  CompletionTokensDetails$inboundSchema,
} from "./completiontokensdetails.js";
import {
  PromptTokensDetails,
  PromptTokensDetails$inboundSchema,
} from "./prompttokensdetails.js";

export type UsageInfoDollarDefs = {
  promptAudioSeconds?: number | null | undefined;
  promptTokens: number;
  totalTokens: number;
  completionTokens?: number | null | undefined;
  requestCount?: number | null | undefined;
  promptTokensDetails?: PromptTokensDetails | null | undefined;
  completionTokensDetails?: CompletionTokensDetails | null | undefined;
  promptTokenDetails?: PromptTokensDetails | null | undefined;
  numCachedTokens?: number | null | undefined;
};

/** @internal */
export const UsageInfoDollarDefs$inboundSchema: z.ZodType<
  UsageInfoDollarDefs,
  unknown
> = z.object({
  prompt_audio_seconds: z.nullable(z.int()).optional(),
  prompt_tokens: z.int().default(0),
  total_tokens: z.int().default(0),
  completion_tokens: z.nullable(z.int()).optional(),
  request_count: z.nullable(z.int()).optional(),
  prompt_tokens_details: z.nullable(PromptTokensDetails$inboundSchema)
    .optional(),
  completion_tokens_details: z.nullable(CompletionTokensDetails$inboundSchema)
    .optional(),
  prompt_token_details: z.nullable(PromptTokensDetails$inboundSchema)
    .optional(),
  num_cached_tokens: z.nullable(z.int()).optional(),
}).transform((v) => {
  return remap$(v, {
    "prompt_audio_seconds": "promptAudioSeconds",
    "prompt_tokens": "promptTokens",
    "total_tokens": "totalTokens",
    "completion_tokens": "completionTokens",
    "request_count": "requestCount",
    "prompt_tokens_details": "promptTokensDetails",
    "completion_tokens_details": "completionTokensDetails",
    "prompt_token_details": "promptTokenDetails",
    "num_cached_tokens": "numCachedTokens",
  });
});

export function usageInfoDollarDefsFromJSON(
  jsonString: string,
): SafeParseResult<UsageInfoDollarDefs, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => UsageInfoDollarDefs$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'UsageInfoDollarDefs' from JSON`,
  );
}
