package automation

import "fmt"

// OperatorHumanForm renders a flow-filter operator into a human-readable
// phrase that mirrors the engine's TRUE-condition semantics defined in
// evaluateRecordFilterForFieldCtx (executor_helpers.go).
//
// Two operators (IsNull, IsBlank) inspect the filter's right-hand
// booleanValue: a value of false flips the predicate. The historical
// lane-runnability misread treated `IsNull booleanValue=false` as
// "field IS NULL" — the engine actually requires the field to BE NOT
// NULL. Calling this helper from the flow-filter-parse CLI keeps the
// rendered "filter must satisfy" report in sync with what the executor
// actually evaluates.
//
// IsNotNull / IsNotBlank / IsChanged have a fixed positive form in the
// executor — the right-hand booleanValue does not flip them — so they
// render as a single phrase regardless of the operand.
//
// rightValue is the unwrapped right-hand operand (after
// extractTypedValue). It is only consulted for the two boolean-flip
// operators above; for all other operators the human form is a fixed
// phrase or symbol and rightValue is unused.
func OperatorHumanForm(operator string, rightValue interface{}) string {
	op := normalizeFlowOperator(operator)
	flip := func(positive, negative string) string {
		if bv, ok := rightValue.(bool); ok && !bv {
			return negative
		}
		return positive
	}
	switch op {
	case "IsNull":
		return flip("IS NULL", "IS NOT NULL")
	case "IsNotNull":
		return "IS NOT NULL"
	case "IsBlank":
		return flip("IS BLANK", "IS NOT BLANK")
	case "IsNotBlank":
		return "IS NOT BLANK"
	case "IsChanged":
		return "IS CHANGED"
	case "EqualTo":
		return "="
	case "NotEqualTo":
		return "!="
	case "GreaterThan":
		return ">"
	case "GreaterThanOrEqualTo":
		return ">="
	case "LessThan":
		return "<"
	case "LessThanOrEqualTo":
		return "<="
	case "Contains":
		return "Contains"
	case "NotContains":
		return "Does Not Contain"
	case "StartsWith":
		return "Starts With"
	case "DoesNotStartWith":
		return "Does Not Start With"
	case "EndsWith":
		return "Ends With"
	case "DoesNotEndWith":
		return "Does Not End With"
	default:
		return fmt.Sprintf("[%s]", op)
	}
}
