<?php
# Generated by the protocol buffer compiler.  DO NOT EDIT!
# NO CHECKED-IN PROTOBUF GENCODE
# source: temporal/api/enums/v1/workflow.proto

namespace Temporal\Api\Enums\V1;

use UnexpectedValueException;

/**
 * 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.
 *
 * Protobuf type <code>temporal.api.enums.v1.WorkflowIdReusePolicy</code>
 */
class WorkflowIdReusePolicy
{
    /**
     * Generated from protobuf enum <code>WORKFLOW_ID_REUSE_POLICY_UNSPECIFIED = 0;</code>
     */
    const WORKFLOW_ID_REUSE_POLICY_UNSPECIFIED = 0;
    /**
     * Allow starting a workflow execution using the same workflow id.
     *
     * Generated from protobuf enum <code>WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE = 1;</code>
     */
    const 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].
     *
     * Generated from protobuf enum <code>WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY = 2;</code>
     */
    const 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.
     *
     * Generated from protobuf enum <code>WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE = 3;</code>
     */
    const WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE = 3;
    /**
     * This option belongs in WorkflowIdConflictPolicy but is here for backwards compatibility.
     * If specified, it acts like ALLOW_DUPLICATE, but also the WorkflowId*Conflict*Policy on
     * the request is treated as WORKFLOW_ID_CONFLICT_POLICY_TERMINATE_EXISTING.
     * If no running workflow, then the behavior is the same as ALLOW_DUPLICATE.
     *
     * Generated from protobuf enum <code>WORKFLOW_ID_REUSE_POLICY_TERMINATE_IF_RUNNING = 4;</code>
     */
    const WORKFLOW_ID_REUSE_POLICY_TERMINATE_IF_RUNNING = 4;

    private static $valueToName = [
        self::WORKFLOW_ID_REUSE_POLICY_UNSPECIFIED => 'WORKFLOW_ID_REUSE_POLICY_UNSPECIFIED',
        self::WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE => 'WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE',
        self::WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY => 'WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY',
        self::WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE => 'WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE',
        self::WORKFLOW_ID_REUSE_POLICY_TERMINATE_IF_RUNNING => 'WORKFLOW_ID_REUSE_POLICY_TERMINATE_IF_RUNNING',
    ];

    public static function name($value)
    {
        if (!isset(self::$valueToName[$value])) {
            throw new UnexpectedValueException(sprintf(
                    'Enum %s has no name defined for value %s', __CLASS__, $value));
        }
        return self::$valueToName[$value];
    }


    public static function value($name)
    {
        $const = __CLASS__ . '::' . strtoupper($name);
        if (!defined($const)) {
            throw new UnexpectedValueException(sprintf(
                    'Enum %s has no value defined for name %s', __CLASS__, $name));
        }
        return constant($const);
    }
}

