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

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 {
  EventProgressStatus,
  EventProgressStatus$inboundSchema,
} from "./eventprogressstatus.js";
import { EventType, EventType$inboundSchema } from "./eventtype.js";
import {
  WorkflowExecutionTraceSummaryAttributesValues,
  WorkflowExecutionTraceSummaryAttributesValues$inboundSchema,
} from "./workflowexecutiontracesummaryattributesvalues.js";

export type WorkflowExecutionProgressTraceEvent = {
  type?: EventType | undefined;
  /**
   * Name of the event
   */
  name: string;
  /**
   * The ID of the event
   */
  id: string;
  /**
   * The timestamp of the event in nanoseconds since the Unix epoch
   */
  timestampUnixNano: number;
  /**
   * The attributes of the event
   */
  attributes: {
    [k: string]: WorkflowExecutionTraceSummaryAttributesValues | null;
  };
  /**
   * Whether the event is internal
   */
  internal: boolean;
  status?: EventProgressStatus | undefined;
  /**
   * The start time of the event in milliseconds since the Unix epoch
   */
  startTimeUnixMs: number;
  /**
   * The end time of the event in milliseconds since the Unix epoch
   */
  endTimeUnixMs?: number | null | undefined;
  /**
   * The error message, if any
   */
  error?: string | null | undefined;
};

/** @internal */
export const WorkflowExecutionProgressTraceEvent$inboundSchema: z.ZodType<
  WorkflowExecutionProgressTraceEvent,
  unknown
> = z.object({
  type: EventType$inboundSchema.optional(),
  name: z.string(),
  id: z.string(),
  timestamp_unix_nano: z.int(),
  attributes: z.record(
    z.string(),
    z.nullable(WorkflowExecutionTraceSummaryAttributesValues$inboundSchema),
  ),
  internal: z.boolean().default(false),
  status: EventProgressStatus$inboundSchema.optional(),
  start_time_unix_ms: z.int(),
  end_time_unix_ms: z.nullable(z.int()).optional(),
  error: z.nullable(z.string()).optional(),
}).transform((v) => {
  return remap$(v, {
    "timestamp_unix_nano": "timestampUnixNano",
    "start_time_unix_ms": "startTimeUnixMs",
    "end_time_unix_ms": "endTimeUnixMs",
  });
});

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