package automation

import (
	"fmt"
	"strings"

	apperrors "github.com/nexuscrm/kernel/pkg/errors"
)

const workflowAlertRuntimeDisabledReason = "WorkflowAlert runtime dispatch is disabled after Flow-native email notification cutover; migrate this dependency to Flow sendEmail or remove it before retrying"

func legacyWorkflowAlertRuntimeDisabledError(surface string) error {
	surface = strings.TrimSpace(surface)
	if surface == "" {
		surface = "WorkflowAlert dependency"
	}
	return apperrors.NewValidationError("WorkflowAlert", fmt.Sprintf("%s cannot execute: %s", surface, workflowAlertRuntimeDisabledReason))
}

func legacyWorkflowAlertRuntimeDisabledFailure(actionName, actionType, surface string) ProcessActionFailure {
	return ProcessActionFailure{
		ActionName: strings.TrimSpace(actionName),
		ActionType: strings.TrimSpace(actionType),
		Reason:     legacyWorkflowAlertRuntimeDisabledError(surface).Error(),
	}
}
