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

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 { smartUnion } from "../../types/smartUnion.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  ActivityTaskCompletedResponse,
  ActivityTaskCompletedResponse$inboundSchema,
} from "./activitytaskcompletedresponse.js";
import {
  ActivityTaskFailedResponse,
  ActivityTaskFailedResponse$inboundSchema,
} from "./activitytaskfailedresponse.js";
import {
  ActivityTaskRetryingResponse,
  ActivityTaskRetryingResponse$inboundSchema,
} from "./activitytaskretryingresponse.js";
import {
  ActivityTaskStartedResponse,
  ActivityTaskStartedResponse$inboundSchema,
} from "./activitytaskstartedresponse.js";
import {
  CustomTaskCanceledResponse,
  CustomTaskCanceledResponse$inboundSchema,
} from "./customtaskcanceledresponse.js";
import {
  CustomTaskCompletedResponse,
  CustomTaskCompletedResponse$inboundSchema,
} from "./customtaskcompletedresponse.js";
import {
  CustomTaskFailedResponse,
  CustomTaskFailedResponse$inboundSchema,
} from "./customtaskfailedresponse.js";
import {
  CustomTaskInProgressResponse,
  CustomTaskInProgressResponse$inboundSchema,
} from "./customtaskinprogressresponse.js";
import {
  CustomTaskStartedResponse,
  CustomTaskStartedResponse$inboundSchema,
} from "./customtaskstartedresponse.js";
import {
  CustomTaskTimedOutResponse,
  CustomTaskTimedOutResponse$inboundSchema,
} from "./customtasktimedoutresponse.js";
import {
  WorkflowExecutionCanceledResponse,
  WorkflowExecutionCanceledResponse$inboundSchema,
} from "./workflowexecutioncanceledresponse.js";
import {
  WorkflowExecutionCompletedResponse,
  WorkflowExecutionCompletedResponse$inboundSchema,
} from "./workflowexecutioncompletedresponse.js";
import {
  WorkflowExecutionContinuedAsNewResponse,
  WorkflowExecutionContinuedAsNewResponse$inboundSchema,
} from "./workflowexecutioncontinuedasnewresponse.js";
import {
  WorkflowExecutionFailedResponse,
  WorkflowExecutionFailedResponse$inboundSchema,
} from "./workflowexecutionfailedresponse.js";
import {
  WorkflowExecutionStartedResponse,
  WorkflowExecutionStartedResponse$inboundSchema,
} from "./workflowexecutionstartedresponse.js";
import {
  WorkflowTaskFailedResponse,
  WorkflowTaskFailedResponse$inboundSchema,
} from "./workflowtaskfailedresponse.js";
import {
  WorkflowTaskTimedOutResponse,
  WorkflowTaskTimedOutResponse$inboundSchema,
} from "./workflowtasktimedoutresponse.js";

export type ListWorkflowEventResponseEvent =
  | WorkflowExecutionStartedResponse
  | WorkflowExecutionCompletedResponse
  | WorkflowExecutionFailedResponse
  | WorkflowExecutionCanceledResponse
  | WorkflowExecutionContinuedAsNewResponse
  | WorkflowTaskTimedOutResponse
  | WorkflowTaskFailedResponse
  | CustomTaskStartedResponse
  | CustomTaskInProgressResponse
  | CustomTaskCompletedResponse
  | CustomTaskFailedResponse
  | CustomTaskTimedOutResponse
  | CustomTaskCanceledResponse
  | ActivityTaskStartedResponse
  | ActivityTaskCompletedResponse
  | ActivityTaskRetryingResponse
  | ActivityTaskFailedResponse;

export type ListWorkflowEventResponse = {
  /**
   * List of workflow events.
   */
  events: Array<
    | WorkflowExecutionStartedResponse
    | WorkflowExecutionCompletedResponse
    | WorkflowExecutionFailedResponse
    | WorkflowExecutionCanceledResponse
    | WorkflowExecutionContinuedAsNewResponse
    | WorkflowTaskTimedOutResponse
    | WorkflowTaskFailedResponse
    | CustomTaskStartedResponse
    | CustomTaskInProgressResponse
    | CustomTaskCompletedResponse
    | CustomTaskFailedResponse
    | CustomTaskTimedOutResponse
    | CustomTaskCanceledResponse
    | ActivityTaskStartedResponse
    | ActivityTaskCompletedResponse
    | ActivityTaskRetryingResponse
    | ActivityTaskFailedResponse
  >;
  /**
   * Cursor for pagination.
   */
  nextCursor?: string | null | undefined;
};

/** @internal */
export const ListWorkflowEventResponseEvent$inboundSchema: z.ZodType<
  ListWorkflowEventResponseEvent,
  unknown
> = smartUnion([
  WorkflowExecutionStartedResponse$inboundSchema,
  WorkflowExecutionCompletedResponse$inboundSchema,
  WorkflowExecutionFailedResponse$inboundSchema,
  WorkflowExecutionCanceledResponse$inboundSchema,
  WorkflowExecutionContinuedAsNewResponse$inboundSchema,
  WorkflowTaskTimedOutResponse$inboundSchema,
  WorkflowTaskFailedResponse$inboundSchema,
  CustomTaskStartedResponse$inboundSchema,
  CustomTaskInProgressResponse$inboundSchema,
  CustomTaskCompletedResponse$inboundSchema,
  CustomTaskFailedResponse$inboundSchema,
  CustomTaskTimedOutResponse$inboundSchema,
  CustomTaskCanceledResponse$inboundSchema,
  ActivityTaskStartedResponse$inboundSchema,
  ActivityTaskCompletedResponse$inboundSchema,
  ActivityTaskRetryingResponse$inboundSchema,
  ActivityTaskFailedResponse$inboundSchema,
]);

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

/** @internal */
export const ListWorkflowEventResponse$inboundSchema: z.ZodType<
  ListWorkflowEventResponse,
  unknown
> = z.object({
  events: z.array(
    smartUnion([
      WorkflowExecutionStartedResponse$inboundSchema,
      WorkflowExecutionCompletedResponse$inboundSchema,
      WorkflowExecutionFailedResponse$inboundSchema,
      WorkflowExecutionCanceledResponse$inboundSchema,
      WorkflowExecutionContinuedAsNewResponse$inboundSchema,
      WorkflowTaskTimedOutResponse$inboundSchema,
      WorkflowTaskFailedResponse$inboundSchema,
      CustomTaskStartedResponse$inboundSchema,
      CustomTaskInProgressResponse$inboundSchema,
      CustomTaskCompletedResponse$inboundSchema,
      CustomTaskFailedResponse$inboundSchema,
      CustomTaskTimedOutResponse$inboundSchema,
      CustomTaskCanceledResponse$inboundSchema,
      ActivityTaskStartedResponse$inboundSchema,
      ActivityTaskCompletedResponse$inboundSchema,
      ActivityTaskRetryingResponse$inboundSchema,
      ActivityTaskFailedResponse$inboundSchema,
    ]),
  ),
  next_cursor: z.nullable(z.string()).optional(),
}).transform((v) => {
  return remap$(v, {
    "next_cursor": "nextCursor",
  });
});

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