/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import * as z from "zod/v4-mini";
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 LLMMetadata = {
  /**
   * The vendor of the event.
   */
  vendor: string;
  /**
   * The model used for the event.
   */
  model: string;
  /**
   * The LLM prompt used for the event.
   */
  prompt?: string | null | undefined;
  /**
   * The LLM response used for the event.
   */
  response?: string | null | undefined;
  /**
   * The number of LLM input tokens used for the event.
   */
  inputTokens: number;
  /**
   * The number of LLM cached tokens that were used for the event.
   */
  cachedInputTokens?: number | undefined;
  /**
   * The number of LLM output tokens used for the event.
   */
  outputTokens: number;
  /**
   * The total number of LLM tokens used for the event.
   */
  totalTokens: number;
};

/** @internal */
export const LLMMetadata$inboundSchema: z.ZodMiniType<LLMMetadata, unknown> = z
  .pipe(
    z.object({
      vendor: z.string(),
      model: z.string(),
      prompt: z.optional(z.nullable(z.string())),
      response: z.optional(z.nullable(z.string())),
      input_tokens: z.int(),
      cached_input_tokens: z.optional(z.int()),
      output_tokens: z.int(),
      total_tokens: z.int(),
    }),
    z.transform((v) => {
      return remap$(v, {
        "input_tokens": "inputTokens",
        "cached_input_tokens": "cachedInputTokens",
        "output_tokens": "outputTokens",
        "total_tokens": "totalTokens",
      });
    }),
  );
/** @internal */
export type LLMMetadata$Outbound = {
  vendor: string;
  model: string;
  prompt?: string | null | undefined;
  response?: string | null | undefined;
  input_tokens: number;
  cached_input_tokens?: number | undefined;
  output_tokens: number;
  total_tokens: number;
};

/** @internal */
export const LLMMetadata$outboundSchema: z.ZodMiniType<
  LLMMetadata$Outbound,
  LLMMetadata
> = z.pipe(
  z.object({
    vendor: z.string(),
    model: z.string(),
    prompt: z.optional(z.nullable(z.string())),
    response: z.optional(z.nullable(z.string())),
    inputTokens: z.int(),
    cachedInputTokens: z.optional(z.int()),
    outputTokens: z.int(),
    totalTokens: z.int(),
  }),
  z.transform((v) => {
    return remap$(v, {
      inputTokens: "input_tokens",
      cachedInputTokens: "cached_input_tokens",
      outputTokens: "output_tokens",
      totalTokens: "total_tokens",
    });
  }),
);

export function llmMetadataToJSON(llmMetadata: LLMMetadata): string {
  return JSON.stringify(LLMMetadata$outboundSchema.parse(llmMetadata));
}
export function llmMetadataFromJSON(
  jsonString: string,
): SafeParseResult<LLMMetadata, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => LLMMetadata$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'LLMMetadata' from JSON`,
  );
}
