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

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 ExecuteWorkflowRegistrationV1WorkflowsRegistrationsWorkflowRegistrationIdExecutePostRequest =
  {
    workflowRegistrationId: string;
    workflowExecutionRequest: components.WorkflowExecutionRequest;
  };

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

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

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

export function executeWorkflowRegistrationV1WorkflowsRegistrationsWorkflowRegistrationIdExecutePostRequestToJSON(
  executeWorkflowRegistrationV1WorkflowsRegistrationsWorkflowRegistrationIdExecutePostRequest:
    ExecuteWorkflowRegistrationV1WorkflowsRegistrationsWorkflowRegistrationIdExecutePostRequest,
): string {
  return JSON.stringify(
    ExecuteWorkflowRegistrationV1WorkflowsRegistrationsWorkflowRegistrationIdExecutePostRequest$outboundSchema
      .parse(
        executeWorkflowRegistrationV1WorkflowsRegistrationsWorkflowRegistrationIdExecutePostRequest,
      ),
  );
}

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

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