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

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 GetSpanStatusCode = {
  Error: "Error",
  Ok: "Ok",
  Unset: "Unset",
} as const;
export type GetSpanStatusCode = OpenEnum<typeof GetSpanStatusCode>;

export type GetSpan = {
  customerId: string;
  organizationId: string;
  workspaceId: string;
  userId: string;
  traceId: string;
  spanId: string;
  parentSpanId: string;
  traceState: string;
  startTime: Date;
  endTime: Date;
  durationNs: number;
  spanName: string;
  spanKind: string;
  serviceName: string;
  statusCode: GetSpanStatusCode;
  statusMessage: string;
  errorType: string;
  operationName: string;
  providerName: string;
  requestModel: string;
  responseModel: string;
  responseId: string;
  outputType: string;
  conversationId: string;
  dataSourceId: string;
  agentId: string;
  agentName: string;
  agentVersion: string;
  agentDescription: string;
  workflowName: string;
  promptName: string;
  toolName: string;
  toolType: string;
  toolCallId: string;
  inputMessages: string;
  outputMessages: string;
  systemInstructions: string;
  toolDefinitions: string;
  toolCallArguments: string;
  toolCallResult: string;
  requestChoiceCount: number;
  requestMaxTokens: number;
  requestTemperature: number | null;
  requestTopP: number | null;
  requestTopK: number | null;
  requestPresencePenalty: number | null;
  requestFrequencyPenalty: number | null;
  requestSeed: number;
  requestStopSequences: Array<string>;
  requestEncodingFormats: Array<string>;
  responseFinishReasons: Array<string>;
  usageInputTokens: number;
  usageOutputTokens: number;
  usageCacheReadInputTokens: number;
  usageCacheCreationInputTokens: number;
  resourceAttributes: { [k: string]: string };
  spanAttributes: { [k: string]: string };
  scopeName: string;
  scopeVersion: string;
};

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

/** @internal */
export const GetSpan$inboundSchema: z.ZodType<GetSpan, unknown> = z.object({
  customer_id: z.string(),
  organization_id: z.string(),
  workspace_id: z.string(),
  user_id: z.string(),
  trace_id: z.string(),
  span_id: z.string(),
  parent_span_id: z.string(),
  trace_state: 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(),
  span_name: z.string(),
  span_kind: z.string(),
  service_name: z.string(),
  status_code: GetSpanStatusCode$inboundSchema,
  status_message: z.string(),
  error_type: z.string(),
  operation_name: z.string(),
  provider_name: z.string(),
  request_model: z.string(),
  response_model: z.string(),
  response_id: z.string(),
  output_type: z.string(),
  conversation_id: z.string(),
  data_source_id: z.string(),
  agent_id: z.string(),
  agent_name: z.string(),
  agent_version: z.string(),
  agent_description: z.string(),
  workflow_name: z.string(),
  prompt_name: z.string(),
  tool_name: z.string(),
  tool_type: z.string(),
  tool_call_id: z.string(),
  input_messages: z.string(),
  output_messages: z.string(),
  system_instructions: z.string(),
  tool_definitions: z.string(),
  tool_call_arguments: z.string(),
  tool_call_result: z.string(),
  request_choice_count: z.int(),
  request_max_tokens: z.int(),
  request_temperature: z.nullable(z.number()),
  request_top_p: z.nullable(z.number()),
  request_top_k: z.nullable(z.number()),
  request_presence_penalty: z.nullable(z.number()),
  request_frequency_penalty: z.nullable(z.number()),
  request_seed: z.int(),
  request_stop_sequences: z.array(z.string()),
  request_encoding_formats: z.array(z.string()),
  response_finish_reasons: z.array(z.string()),
  usage_input_tokens: z.int(),
  usage_output_tokens: z.int(),
  usage_cache_read_input_tokens: z.int(),
  usage_cache_creation_input_tokens: z.int(),
  resource_attributes: z.record(z.string(), z.string()),
  span_attributes: z.record(z.string(), z.string()),
  scope_name: z.string(),
  scope_version: z.string(),
}).transform((v) => {
  return remap$(v, {
    "customer_id": "customerId",
    "organization_id": "organizationId",
    "workspace_id": "workspaceId",
    "user_id": "userId",
    "trace_id": "traceId",
    "span_id": "spanId",
    "parent_span_id": "parentSpanId",
    "trace_state": "traceState",
    "start_time": "startTime",
    "end_time": "endTime",
    "duration_ns": "durationNs",
    "span_name": "spanName",
    "span_kind": "spanKind",
    "service_name": "serviceName",
    "status_code": "statusCode",
    "status_message": "statusMessage",
    "error_type": "errorType",
    "operation_name": "operationName",
    "provider_name": "providerName",
    "request_model": "requestModel",
    "response_model": "responseModel",
    "response_id": "responseId",
    "output_type": "outputType",
    "conversation_id": "conversationId",
    "data_source_id": "dataSourceId",
    "agent_id": "agentId",
    "agent_name": "agentName",
    "agent_version": "agentVersion",
    "agent_description": "agentDescription",
    "workflow_name": "workflowName",
    "prompt_name": "promptName",
    "tool_name": "toolName",
    "tool_type": "toolType",
    "tool_call_id": "toolCallId",
    "input_messages": "inputMessages",
    "output_messages": "outputMessages",
    "system_instructions": "systemInstructions",
    "tool_definitions": "toolDefinitions",
    "tool_call_arguments": "toolCallArguments",
    "tool_call_result": "toolCallResult",
    "request_choice_count": "requestChoiceCount",
    "request_max_tokens": "requestMaxTokens",
    "request_temperature": "requestTemperature",
    "request_top_p": "requestTopP",
    "request_top_k": "requestTopK",
    "request_presence_penalty": "requestPresencePenalty",
    "request_frequency_penalty": "requestFrequencyPenalty",
    "request_seed": "requestSeed",
    "request_stop_sequences": "requestStopSequences",
    "request_encoding_formats": "requestEncodingFormats",
    "response_finish_reasons": "responseFinishReasons",
    "usage_input_tokens": "usageInputTokens",
    "usage_output_tokens": "usageOutputTokens",
    "usage_cache_read_input_tokens": "usageCacheReadInputTokens",
    "usage_cache_creation_input_tokens": "usageCacheCreationInputTokens",
    "resource_attributes": "resourceAttributes",
    "span_attributes": "spanAttributes",
    "scope_name": "scopeName",
    "scope_version": "scopeVersion",
  });
});

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