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

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import * as openEnums from "../../types/enums.js";
import { OpenEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export const GetTraceStatusCode = {
  Error: "Error",
  Unset: "Unset",
} as const;
export type GetTraceStatusCode = OpenEnum<typeof GetTraceStatusCode>;

export type GetTrace = {
  customerId: string;
  organizationId: string;
  workspaceId: string;
  userId: string;
  traceId: string;
  rootSpanId: string;
  rootSpanName: string;
  startTime: Date;
  endTime: Date;
  durationNs: number;
  serviceName: string;
  environment: string;
  conversationId: string;
  workflowName: string;
  agentId: string;
  agentName: string;
  statusCode: GetTraceStatusCode;
  errorCount: number;
  spanCount: number;
  genAiSpanCount: number;
  llmCallCount: number;
  toolCallCount: number;
  retrievalCount: number;
  evaluationCount: number;
  inputTokens: number;
  outputTokens: number;
  cacheReadInputTokens: number;
  cacheCreationInputTokens: number;
  modelsUsed: Array<string>;
  toolsUsed: Array<string>;
  firstTurnLastInputMessage: string;
  firstTurnLastOutputMessage: string;
  lastTurnLastInputMessage: string;
  lastTurnLastOutputMessage: string;
};

/** @internal */
export const GetTraceStatusCode$inboundSchema: z.ZodType<
  GetTraceStatusCode,
  unknown
> = openEnums.inboundSchema(GetTraceStatusCode);

/** @internal */
export const GetTrace$inboundSchema: z.ZodType<GetTrace, unknown> = z.object({
  customer_id: z.string(),
  organization_id: z.string(),
  workspace_id: z.string(),
  user_id: z.string(),
  trace_id: z.string(),
  root_span_id: z.string(),
  root_span_name: z.string(),
  start_time: z.iso.datetime({ offset: true }).transform(v => new Date(v)),
  end_time: z.iso.datetime({ offset: true }).transform(v => new Date(v)),
  duration_ns: z.int(),
  service_name: z.string(),
  environment: z.string(),
  conversation_id: z.string(),
  workflow_name: z.string(),
  agent_id: z.string(),
  agent_name: z.string(),
  status_code: GetTraceStatusCode$inboundSchema,
  error_count: z.int(),
  span_count: z.int(),
  gen_ai_span_count: z.int(),
  llm_call_count: z.int(),
  tool_call_count: z.int(),
  retrieval_count: z.int(),
  evaluation_count: z.int(),
  input_tokens: z.int(),
  output_tokens: z.int(),
  cache_read_input_tokens: z.int(),
  cache_creation_input_tokens: z.int(),
  models_used: z.array(z.string()),
  tools_used: z.array(z.string()),
  first_turn_last_input_message: z.string(),
  first_turn_last_output_message: z.string(),
  last_turn_last_input_message: z.string(),
  last_turn_last_output_message: z.string(),
}).transform((v) => {
  return remap$(v, {
    "customer_id": "customerId",
    "organization_id": "organizationId",
    "workspace_id": "workspaceId",
    "user_id": "userId",
    "trace_id": "traceId",
    "root_span_id": "rootSpanId",
    "root_span_name": "rootSpanName",
    "start_time": "startTime",
    "end_time": "endTime",
    "duration_ns": "durationNs",
    "service_name": "serviceName",
    "conversation_id": "conversationId",
    "workflow_name": "workflowName",
    "agent_id": "agentId",
    "agent_name": "agentName",
    "status_code": "statusCode",
    "error_count": "errorCount",
    "span_count": "spanCount",
    "gen_ai_span_count": "genAiSpanCount",
    "llm_call_count": "llmCallCount",
    "tool_call_count": "toolCallCount",
    "retrieval_count": "retrievalCount",
    "evaluation_count": "evaluationCount",
    "input_tokens": "inputTokens",
    "output_tokens": "outputTokens",
    "cache_read_input_tokens": "cacheReadInputTokens",
    "cache_creation_input_tokens": "cacheCreationInputTokens",
    "models_used": "modelsUsed",
    "tools_used": "toolsUsed",
    "first_turn_last_input_message": "firstTurnLastInputMessage",
    "first_turn_last_output_message": "firstTurnLastOutputMessage",
    "last_turn_last_input_message": "lastTurnLastInputMessage",
    "last_turn_last_output_message": "lastTurnLastOutputMessage",
  });
});

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