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

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 * as components from "../components/index.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export type ExecuteWorkflowV1WorkflowsWorkflowIdentifierExecutePostRequest = {
  workflowIdentifier: string;
  workflowExecutionRequest: components.WorkflowExecutionRequest;
};

/**
 * Successful Response
 */
export type ResponseExecuteWorkflowV1WorkflowsWorkflowIdentifierExecutePost =
  | components.WorkflowExecutionResponse
  | components.WorkflowExecutionSyncResponse;

/** @internal */
export type ExecuteWorkflowV1WorkflowsWorkflowIdentifierExecutePostRequest$Outbound =
  {
    workflow_identifier: string;
    WorkflowExecutionRequest: components.WorkflowExecutionRequest$Outbound;
  };

/** @internal */
export const ExecuteWorkflowV1WorkflowsWorkflowIdentifierExecutePostRequest$outboundSchema:
  z.ZodType<
    ExecuteWorkflowV1WorkflowsWorkflowIdentifierExecutePostRequest$Outbound,
    ExecuteWorkflowV1WorkflowsWorkflowIdentifierExecutePostRequest
  > = z.object({
    workflowIdentifier: z.string(),
    workflowExecutionRequest:
      components.WorkflowExecutionRequest$outboundSchema,
  }).transform((v) => {
    return remap$(v, {
      workflowIdentifier: "workflow_identifier",
      workflowExecutionRequest: "WorkflowExecutionRequest",
    });
  });

export function executeWorkflowV1WorkflowsWorkflowIdentifierExecutePostRequestToJSON(
  executeWorkflowV1WorkflowsWorkflowIdentifierExecutePostRequest:
    ExecuteWorkflowV1WorkflowsWorkflowIdentifierExecutePostRequest,
): string {
  return JSON.stringify(
    ExecuteWorkflowV1WorkflowsWorkflowIdentifierExecutePostRequest$outboundSchema
      .parse(executeWorkflowV1WorkflowsWorkflowIdentifierExecutePostRequest),
  );
}

/** @internal */
export const ResponseExecuteWorkflowV1WorkflowsWorkflowIdentifierExecutePost$inboundSchema:
  z.ZodType<
    ResponseExecuteWorkflowV1WorkflowsWorkflowIdentifierExecutePost,
    unknown
  > = smartUnion([
    components.WorkflowExecutionResponse$inboundSchema,
    components.WorkflowExecutionSyncResponse$inboundSchema,
  ]);

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