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

import * as z from "zod/v4";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  TempoTraceAttribute,
  TempoTraceAttribute$inboundSchema,
} from "./tempotraceattribute.js";
import {
  TempoTraceEvent,
  TempoTraceEvent$inboundSchema,
} from "./tempotraceevent.js";
import {
  TempoTraceScopeKind,
  TempoTraceScopeKind$inboundSchema,
} from "./tempotracescopekind.js";

export type TempoTraceSpan = {
  /**
   * The trace ID of the scope
   */
  traceId: string;
  /**
   * The span ID of the scope
   */
  spanId: string;
  /**
   * The parent span ID of the scope
   */
  parentSpanId?: string | null | undefined;
  /**
   * The name of the scope
   */
  name: string;
  kind: TempoTraceScopeKind;
  /**
   * The start time of the scope in Unix nano
   */
  startTimeUnixNano: string;
  /**
   * The end time of the scope in Unix nano
   */
  endTimeUnixNano: string;
  /**
   * The attributes of the scope
   */
  attributes?: Array<TempoTraceAttribute> | undefined;
  /**
   * The events of the scope
   */
  events?: Array<TempoTraceEvent> | undefined;
};

/** @internal */
export const TempoTraceSpan$inboundSchema: z.ZodType<TempoTraceSpan, unknown> =
  z.object({
    traceId: z.string(),
    spanId: z.string(),
    parentSpanId: z.nullable(z.string()).optional(),
    name: z.string(),
    kind: TempoTraceScopeKind$inboundSchema,
    startTimeUnixNano: z.string(),
    endTimeUnixNano: z.string(),
    attributes: z.array(TempoTraceAttribute$inboundSchema).optional(),
    events: z.array(TempoTraceEvent$inboundSchema).optional(),
  });

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