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

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 ConversationUsageInfo = {
  promptTokens: number;
  completionTokens: number;
  totalTokens: number;
  connectorTokens?: number | null | undefined;
  connectors?: { [k: string]: number } | null | undefined;
};

/** @internal */
export const ConversationUsageInfo$inboundSchema: z.ZodType<
  ConversationUsageInfo,
  unknown
> = z.object({
  prompt_tokens: z.int().default(0),
  completion_tokens: z.int().default(0),
  total_tokens: z.int().default(0),
  connector_tokens: z.nullable(z.int()).optional(),
  connectors: z.nullable(z.record(z.string(), z.int())).optional(),
}).transform((v) => {
  return remap$(v, {
    "prompt_tokens": "promptTokens",
    "completion_tokens": "completionTokens",
    "total_tokens": "totalTokens",
    "connector_tokens": "connectorTokens",
  });
});

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