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

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

export type WorkflowExecutionTraceEvent = {
  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;
};

/** @internal */
export const WorkflowExecutionTraceEvent$inboundSchema: z.ZodType<
  WorkflowExecutionTraceEvent,
  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),
}).transform((v) => {
  return remap$(v, {
    "timestamp_unix_nano": "timestampUnixNano",
  });
});

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