syntax = "proto3";

package temporal.api.enums.v1;

option go_package = "go.temporal.io/api/enums/v1;enums";
option java_package = "io.temporal.api.enums.v1";
option java_multiple_files = true;
option java_outer_classname = "WorkflowProto";
option ruby_package = "Temporalio::Api::Enums::V1";
option csharp_namespace = "Temporalio.Api.Enums.V1";

// Defines whether to allow re-using a workflow id from a previously *closed* workflow.
// If the request is denied, the server returns a `WorkflowExecutionAlreadyStartedFailure` error.
//
// See `WorkflowIdConflictPolicy` for handling workflow id duplication with a *running* workflow.
enum WorkflowIdReusePolicy {
    WORKFLOW_ID_REUSE_POLICY_UNSPECIFIED = 0;
    // Allow starting a workflow execution using the same workflow id.
    WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE = 1;
    // Allow starting a workflow execution using the same workflow id, only when the last
    // execution's final state is one of [terminated, cancelled, timed out, failed].
    WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY = 2;
    // Do not permit re-use of the workflow id for this workflow. Future start workflow requests
    // could potentially change the policy, allowing re-use of the workflow id.
    WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE = 3;
    // Terminate the current Workflow if one is already running; otherwise allow reusing the
    // Workflow ID. When using this option, `WorkflowIdConflictPolicy` must be left unspecified.
    //
    // Deprecated. Instead, set `WorkflowIdReusePolicy` to `ALLOW_DUPLICATE` and
    // `WorkflowIdConflictPolicy` to `TERMINATE_EXISTING`. Note that `WorkflowIdConflictPolicy`
    // requires Temporal Server v1.24.0 or later.
    WORKFLOW_ID_REUSE_POLICY_TERMINATE_IF_RUNNING = 4 [deprecated = true];
}

// Defines what to do when trying to start a workflow with the same workflow id as a *running* workflow.
// Note that it is *never* valid to have two actively running instances of the same workflow id.
//
// See `WorkflowIdReusePolicy` for handling workflow id duplication with a *closed* workflow.
enum WorkflowIdConflictPolicy {
    WORKFLOW_ID_CONFLICT_POLICY_UNSPECIFIED = 0;
    // Don't start a new workflow; instead return `WorkflowExecutionAlreadyStartedFailure`.
    WORKFLOW_ID_CONFLICT_POLICY_FAIL = 1;
    // Don't start a new workflow; instead return a workflow handle for the running workflow.
    WORKFLOW_ID_CONFLICT_POLICY_USE_EXISTING = 2;
    // Terminate the running workflow before starting a new one.
    WORKFLOW_ID_CONFLICT_POLICY_TERMINATE_EXISTING = 3;
}

// Defines how child workflows will react to their parent completing
enum ParentClosePolicy {
    PARENT_CLOSE_POLICY_UNSPECIFIED = 0;
    // The child workflow will also terminate
    PARENT_CLOSE_POLICY_TERMINATE = 1;
    // The child workflow will do nothing
    PARENT_CLOSE_POLICY_ABANDON = 2;
    // Cancellation will be requested of the child workflow
    PARENT_CLOSE_POLICY_REQUEST_CANCEL = 3;
}

enum ContinueAsNewInitiator {
    CONTINUE_AS_NEW_INITIATOR_UNSPECIFIED = 0;
    // The workflow itself requested to continue as new
    CONTINUE_AS_NEW_INITIATOR_WORKFLOW = 1;
    // The workflow continued as new because it is retrying
    CONTINUE_AS_NEW_INITIATOR_RETRY = 2;
    // The workflow continued as new because cron has triggered a new execution
    CONTINUE_AS_NEW_INITIATOR_CRON_SCHEDULE = 3;
}

// (-- api-linter: core::0216::synonyms=disabled
//     aip.dev/not-precedent: There is WorkflowExecutionState already in another package. --)
enum WorkflowExecutionStatus {
    WORKFLOW_EXECUTION_STATUS_UNSPECIFIED = 0;
    // Value 1 is hardcoded in SQL persistence.
    WORKFLOW_EXECUTION_STATUS_RUNNING = 1;
    WORKFLOW_EXECUTION_STATUS_COMPLETED = 2;
    WORKFLOW_EXECUTION_STATUS_FAILED = 3;
    WORKFLOW_EXECUTION_STATUS_CANCELED = 4;
    WORKFLOW_EXECUTION_STATUS_TERMINATED = 5;
    WORKFLOW_EXECUTION_STATUS_CONTINUED_AS_NEW = 6;
    WORKFLOW_EXECUTION_STATUS_TIMED_OUT = 7;
    WORKFLOW_EXECUTION_STATUS_PAUSED = 8;
}

enum PendingActivityState {
    PENDING_ACTIVITY_STATE_UNSPECIFIED = 0;
    PENDING_ACTIVITY_STATE_SCHEDULED = 1;
    PENDING_ACTIVITY_STATE_STARTED = 2;
    PENDING_ACTIVITY_STATE_CANCEL_REQUESTED = 3;
    // PAUSED means activity is paused on the server, and is not running in the worker
    PENDING_ACTIVITY_STATE_PAUSED = 4;
    // PAUSE_REQUESTED means activity is currently running on the worker, but paused on the server
    PENDING_ACTIVITY_STATE_PAUSE_REQUESTED = 5;
}

enum PendingWorkflowTaskState {
    PENDING_WORKFLOW_TASK_STATE_UNSPECIFIED = 0;
    PENDING_WORKFLOW_TASK_STATE_SCHEDULED = 1;
    PENDING_WORKFLOW_TASK_STATE_STARTED = 2;
}

enum HistoryEventFilterType {
    HISTORY_EVENT_FILTER_TYPE_UNSPECIFIED = 0;
    HISTORY_EVENT_FILTER_TYPE_ALL_EVENT = 1;
    HISTORY_EVENT_FILTER_TYPE_CLOSE_EVENT = 2;
}

enum RetryState {
    RETRY_STATE_UNSPECIFIED = 0;
    RETRY_STATE_IN_PROGRESS = 1;
    RETRY_STATE_NON_RETRYABLE_FAILURE = 2;
    RETRY_STATE_TIMEOUT = 3;
    RETRY_STATE_MAXIMUM_ATTEMPTS_REACHED = 4;
    RETRY_STATE_RETRY_POLICY_NOT_SET = 5;
    RETRY_STATE_INTERNAL_SERVER_ERROR = 6;
    RETRY_STATE_CANCEL_REQUESTED = 7;
}

enum TimeoutType {
    TIMEOUT_TYPE_UNSPECIFIED = 0;
    TIMEOUT_TYPE_START_TO_CLOSE = 1;
    TIMEOUT_TYPE_SCHEDULE_TO_START = 2;
    TIMEOUT_TYPE_SCHEDULE_TO_CLOSE = 3;
    TIMEOUT_TYPE_HEARTBEAT = 4;
}

// Versioning Behavior specifies if and how a workflow execution moves between Worker Deployment
// Versions. The Versioning Behavior of a workflow execution is typically specified by the worker
// who completes the first task of the execution, but is also overridable manually for new and
// existing workflows (see VersioningOverride).
enum VersioningBehavior {
    // Workflow execution does not have a Versioning Behavior and is called Unversioned. This is the
    // legacy behavior. An Unversioned workflow's task can go to any Unversioned worker (see
    // `WorkerVersioningMode`.)
    // User needs to use Patching to keep the new code compatible with prior versions when dealing
    // with Unversioned workflows.
    VERSIONING_BEHAVIOR_UNSPECIFIED = 0;
    // Workflow will start on its Target Version and then will be pinned to that same Deployment
    // Version until completion (the Version that this Workflow is pinned to is specified in
    // `versioning_info.version` and is the Pinned Version of the Workflow).
    //
    // The workflow's Target Version is the Current Version of its Task Queue, or, if the
    // Task Queue has a Ramping Version with non-zero Ramp Percentage `P`, the workflow's Target
    // Version has a P% chance of being the Ramping Version. Whether a workflow falls into the
    // Ramping group depends on its Workflow ID and and the Ramp Percentage.
    //
    // This behavior eliminates most of compatibility concerns users face when changing their code.
    // Patching is not needed when pinned workflows code change.
    // Can be overridden explicitly via `UpdateWorkflowExecutionOptions` API to move the
    // execution to another Deployment Version.
    // Activities of `PINNED` workflows are sent to the same Deployment Version. Exception to this
    // would be when the activity Task Queue workers are not present in the workflow's Deployment
    // Version, in which case the activity will be sent to the Current Deployment Version of its own
    // task queue.
    VERSIONING_BEHAVIOR_PINNED = 1;
    // Workflow will automatically move to its Target Version when the next workflow task is dispatched.
    //
    // The workflow's Target Version is the Current Version of its Task Queue, or, if the
    // Task Queue has a Ramping Version with non-zero Ramp Percentage `P`, the workflow's Target
    // Version has a P% chance of being the Ramping Version. Whether a workflow falls into the
    // Ramping group depends on its Workflow ID and and the Ramp Percentage.
    //
    // AutoUpgrade behavior is suitable for long-running workflows as it allows them to move to the
    // latest Deployment Version, but the user still needs to use Patching to keep the new code
    // compatible with prior versions for changed workflow types.
    // Activities of `AUTO_UPGRADE` workflows are sent to the Deployment Version of the workflow
    // execution (as specified in versioning_info.version based on the last completed
    // workflow task). Exception to this would be when the activity Task Queue workers are not
    // present in the workflow's Deployment Version, in which case, the activity will be sent to a
    // different Deployment Version according to the Current or Ramping Deployment Version of its own
    // Task Queue.
    // Workflows stuck on a backlogged activity will still auto-upgrade if their Target Version
    // changes, without having to wait for the backlogged activity to complete on the old Version.
    VERSIONING_BEHAVIOR_AUTO_UPGRADE = 2;
}

// Experimental. Defines the versioning behavior to be used by the first task of a new workflow run in a continue-as-new chain.
enum ContinueAsNewVersioningBehavior {
    CONTINUE_AS_NEW_VERSIONING_BEHAVIOR_UNSPECIFIED = 0;

    // Experimental.
    // Start the new run with AutoUpgrade behavior. Use the Target Version of the workflow's task queue at
    // start-time, as AutoUpgrade workflows do. After the first workflow task completes, use whatever
    // Versioning Behavior the workflow is annotated with in the workflow code.
    //
    // Note that if the workflow being continued has a Pinned override, that override will be inherited by the
    // new workflow run regardless of the ContinueAsNewVersioningBehavior specified in the continue-as-new
    // command. Versioning Override always takes precedence until it's removed manually via UpdateWorkflowExecutionOptions.
    CONTINUE_AS_NEW_VERSIONING_BEHAVIOR_AUTO_UPGRADE = 1;

    // Experimental.
    // Use the Ramping Version of the workflow's task queue at start time, regardless of the workflow's
    // Target Version (according to f(workflow_id, ramp_percentage)). After the first workflow task completes,
    // the workflow will use whatever Versioning Behavior it is annotated with. If there is no Ramping
    // Version by the time that the first workflow task is dispatched, it will be sent to the Current Version.
    //
    // It is highly discouraged to use this if the workflow is annotated with AutoUpgrade behavior, because
    // this setting ONLY applies to the first task of the workflow. If, after the first task, the workflow
    // is AutoUpgrade, it will behave like a normal AutoUpgrade workflow and go to the Target Version, which
    // may be the Current Version instead of the Ramping Version.
    //
    // Note that if the workflow being continued has a Pinned override, that override will be inherited by the
    // new workflow run regardless of the ContinueAsNewVersioningBehavior specified in the continue-as-new
    // command. Versioning Override always takes precedence until it's removed manually via UpdateWorkflowExecutionOptions.
    CONTINUE_AS_NEW_VERSIONING_BEHAVIOR_USE_RAMPING_VERSION = 2;
}

// SuggestContinueAsNewReason specifies why SuggestContinueAsNew is true.
enum SuggestContinueAsNewReason {
    SUGGEST_CONTINUE_AS_NEW_REASON_UNSPECIFIED = 0;

    // Workflow History size is getting too large.
    SUGGEST_CONTINUE_AS_NEW_REASON_HISTORY_SIZE_TOO_LARGE = 1;

    // Workflow History event count is getting too large.
    SUGGEST_CONTINUE_AS_NEW_REASON_TOO_MANY_HISTORY_EVENTS = 2;

    // Workflow's count of completed plus in-flight updates is too large.
    SUGGEST_CONTINUE_AS_NEW_REASON_TOO_MANY_UPDATES = 3;

    // TARGET_WORKER_DEPLOYMENT_VERSION_CHANGED is no longer a reason for suggest_continue_as_new.
    // See target_worker_deployment_version_changed to find out if Target Version Changed.
    reserved 4;
    reserved "SUGGEST_CONTINUE_AS_NEW_REASON_TARGET_WORKER_DEPLOYMENT_VERSION_CHANGED";
}
