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

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 { MessageTokens, MessageTokens$inboundSchema } from "./messagetokens.js";

/**
 * Token usage details for the prompt.
 */
export type PromptTokensDetails = {
  messages?: Array<MessageTokens> | undefined;
  cachedTokens: number;
  audioTokens: number;
};

/** @internal */
export const PromptTokensDetails$inboundSchema: z.ZodType<
  PromptTokensDetails,
  unknown
> = z.object({
  messages: z.array(MessageTokens$inboundSchema).optional(),
  cached_tokens: z.int().default(0),
  audio_tokens: z.int().default(0),
}).transform((v) => {
  return remap$(v, {
    "cached_tokens": "cachedTokens",
    "audio_tokens": "audioTokens",
  });
});

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