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

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 {
  QueryDefinition,
  QueryDefinition$inboundSchema,
} from "./querydefinition.js";
import {
  SignalDefinition,
  SignalDefinition$inboundSchema,
} from "./signaldefinition.js";
import {
  UpdateDefinition,
  UpdateDefinition$inboundSchema,
} from "./updatedefinition.js";

export type WorkflowCodeDefinition = {
  /**
   * Input schema of the workflow's run method
   */
  inputSchema: { [k: string]: any };
  /**
   * Output schema of the workflow's run method
   */
  outputSchema?: { [k: string]: any } | null | undefined;
  /**
   * Signal handlers defined by the workflow
   */
  signals?: Array<SignalDefinition> | undefined;
  /**
   * Query handlers defined by the workflow
   */
  queries?: Array<QueryDefinition> | undefined;
  /**
   * Update handlers defined by the workflow
   */
  updates?: Array<UpdateDefinition> | undefined;
  /**
   * Whether the workflow enforces deterministic execution
   */
  enforceDeterminism: boolean;
  /**
   * Maximum total execution time including retries and continue-as-new
   */
  executionTimeout?: number | undefined;
  /**
   * Plugin-specific metadata (e.g. connector declarations)
   */
  pluginMetadata?: { [k: string]: any } | null | undefined;
};

/** @internal */
export const WorkflowCodeDefinition$inboundSchema: z.ZodType<
  WorkflowCodeDefinition,
  unknown
> = z.object({
  input_schema: z.record(z.string(), z.any()),
  output_schema: z.nullable(z.record(z.string(), z.any())).optional(),
  signals: z.array(SignalDefinition$inboundSchema).optional(),
  queries: z.array(QueryDefinition$inboundSchema).optional(),
  updates: z.array(UpdateDefinition$inboundSchema).optional(),
  enforce_determinism: z.boolean().default(false),
  execution_timeout: z.number().optional(),
  plugin_metadata: z.nullable(z.record(z.string(), z.any())).optional(),
}).transform((v) => {
  return remap$(v, {
    "input_schema": "inputSchema",
    "output_schema": "outputSchema",
    "enforce_determinism": "enforceDeterminism",
    "execution_timeout": "executionTimeout",
    "plugin_metadata": "pluginMetadata",
  });
});

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