func ValidateUpdateWorkflowStateStatus(
	state enumsspb.WorkflowExecutionState,
	status enumspb.WorkflowExecutionStatus,
) error {
	if err := validateWorkflowState(state); err != nil {
		return err
	}
	if err := validateWorkflowStatus(status); err != nil {
		return err
	}
	if status == enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING {
		if state == enumsspb.WORKFLOW_EXECUTION_STATE_COMPLETED {
			return serviceerror.NewInternal(fmt.Sprintf("Update workflow with invalid state: %v or status: %v", state, status))
		}
	} else {
		if state != enumsspb.WORKFLOW_EXECUTION_STATE_COMPLETED {
			return serviceerror.NewInternal(fmt.Sprintf("Update workflow with invalid state: %v or status: %v", state, status))
		}
	}
	return nil
}
ValidateUpdateWorkflowStateStatus validate workflow state and status
package persistence
import (
	"fmt"
	enumspb "go.temporal.io/api/enums/v1"
	"go.temporal.io/api/serviceerror"
	enumsspb "go.temporal.io/server/api/enums/v1"
)
var (
	validWorkflowStates = map[enumsspb.WorkflowExecutionState]struct{}{
		enumsspb.WORKFLOW_EXECUTION_STATE_CREATED:   {},
		enumsspb.WORKFLOW_EXECUTION_STATE_RUNNING:   {},
		enumsspb.WORKFLOW_EXECUTION_STATE_COMPLETED: {},
		enumsspb.WORKFLOW_EXECUTION_STATE_ZOMBIE:    {},
		enumsspb.WORKFLOW_EXECUTION_STATE_CORRUPTED: {},
	}
	validWorkflowStatuses = map[enumspb.WorkflowExecutionStatus]struct{}{
		enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING:          {},
		enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED:        {},
		enumspb.WORKFLOW_EXECUTION_STATUS_FAILED:           {},
		enumspb.WORKFLOW_EXECUTION_STATUS_CANCELED:         {},
		enumspb.WORKFLOW_EXECUTION_STATUS_TERMINATED:       {},
		enumspb.WORKFLOW_EXECUTION_STATUS_CONTINUED_AS_NEW: {},
		enumspb.WORKFLOW_EXECUTION_STATUS_TIMED_OUT:        {},
	}
)
func ValidateCreateWorkflowStateStatus(
	state enumsspb.WorkflowExecutionState,
	status enumspb.WorkflowExecutionStatus,
) error {
	if err := validateWorkflowState(state); err != nil {
		return err
	}
	if err := validateWorkflowStatus(status); err != nil {
		return err
	}
	if state == enumsspb.WORKFLOW_EXECUTION_STATE_COMPLETED || status != enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING {
		return serviceerror.NewInternal(fmt.Sprintf("Create workflow with invalid state: %v or status: %v", state, status))
	}
	return nil
}