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

import * as z from "zod/v4";
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";
import {
  WorkflowExecutionTraceEvent,
  WorkflowExecutionTraceEvent$inboundSchema,
} from "./workflowexecutiontraceevent.js";
import {
  WorkflowExecutionTraceSummaryAttributesValues,
  WorkflowExecutionTraceSummaryAttributesValues$inboundSchema,
} from "./workflowexecutiontracesummaryattributesvalues.js";

export type WorkflowExecutionTraceSummarySpan = {
  /**
   * The ID of the span
   */
  spanId: string;
  /**
   * The name of the span
   */
  name: string;
  /**
   * The start time of the span in nanoseconds since the Unix epoch
   */
  startTimeUnixNano: number;
  /**
   * The end time of the span in nanoseconds since the Unix epoch
   */
  endTimeUnixNano: number | null;
  /**
   * The attributes of the span
   */
  attributes: {
    [k: string]: WorkflowExecutionTraceSummaryAttributesValues | null;
  };
  /**
   * The events of the span
   */
  events: Array<WorkflowExecutionTraceEvent>;
  /**
   * The child spans of the span
   */
  children?: Array<WorkflowExecutionTraceSummarySpan> | undefined;
};

/** @internal */
export const WorkflowExecutionTraceSummarySpan$inboundSchema: z.ZodType<
  WorkflowExecutionTraceSummarySpan,
  unknown
> = z.object({
  span_id: z.string(),
  name: z.string(),
  start_time_unix_nano: z.int(),
  end_time_unix_nano: z.nullable(z.int()),
  attributes: z.record(
    z.string(),
    z.nullable(WorkflowExecutionTraceSummaryAttributesValues$inboundSchema),
  ),
  events: z.array(WorkflowExecutionTraceEvent$inboundSchema),
  children: z.array(
    z.lazy(() => WorkflowExecutionTraceSummarySpan$inboundSchema),
  ).optional(),
}).transform((v) => {
  return remap$(v, {
    "span_id": "spanId",
    "start_time_unix_nano": "startTimeUnixNano",
    "end_time_unix_nano": "endTimeUnixNano",
  });
});

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