/*
 * 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 { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export type ConversationUsageInfo = {
  promptTokens: number | undefined;
  completionTokens: number | undefined;
  totalTokens: number | undefined;
  connectorTokens?: number | null | undefined;
  connectors?: { [k: string]: number } | null | undefined;
};

/** @internal */
export const ConversationUsageInfo$inboundSchema: z.ZodType<
  ConversationUsageInfo,
  z.ZodTypeDef,
  unknown
> = z.object({
  prompt_tokens: z.number().int().default(0),
  completion_tokens: z.number().int().default(0),
  total_tokens: z.number().int().default(0),
  connector_tokens: z.nullable(z.number().int()).optional(),
  connectors: z.nullable(z.record(z.number().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`,
  );
}
