package constants

import "testing"

// TestProcessActionTypeWireValues locks the persisted ProcessAction.ActionType
// wire strings. These values are written to records; a rename of the Go
// identifier must never silently change them.
func TestProcessActionTypeWireValues(t *testing.T) {
	tests := []struct {
		name string
		got  string
		want string
	}{
		{"ProcessActionTypeFieldUpdate", ProcessActionTypeFieldUpdate, "FieldUpdate"},
		{"ProcessActionTypeAlert", ProcessActionTypeAlert, "Alert"},
		{"ProcessActionTypeFlow", ProcessActionTypeFlow, "Flow"},
	}
	for _, tt := range tests {
		if tt.got != tt.want {
			t.Errorf("%s = %q, want %q (wire value is load-bearing for persisted ProcessAction.ActionType and v63 parity)", tt.name, tt.got, tt.want)
		}
	}
}

// TestProcessActionTypeSeparateFromAutomationActionType guards the taxonomy
// boundary: the approval side-effect taxonomy (ProcessActionType*) and the
// automation dispatch-mechanism taxonomy (ActionType* in actions.go) are
// distinct axes and MUST NOT collapse into one shared value set. If a future
// edit makes an approval ProcessActionType* value equal an automation
// ActionType* value, the two enums have started to merge — fail loudly.
func TestProcessActionTypeSeparateFromAutomationActionType(t *testing.T) {
	automationActionTypes := map[string]string{
		ActionTypeCreateRecord:      "ActionTypeCreateRecord",
		ActionTypeUpdateRecord:      "ActionTypeUpdateRecord",
		ActionTypeDeleteRecord:      "ActionTypeDeleteRecord",
		ActionTypeSendEmail:         "ActionTypeSendEmail",
		ActionTypeCallWebhook:       "ActionTypeCallWebhook",
		ActionTypePushToConnector:   "ActionTypePushToConnector",
		ActionTypeComposite:         "ActionTypeComposite",
		ActionTypeExecuteAction:     "ActionTypeExecuteAction",
		ActionTypeSubmitForApproval: "ActionTypeSubmitForApproval",
	}

	processActionTypes := []struct {
		name  string
		value string
	}{
		{"ProcessActionTypeFieldUpdate", ProcessActionTypeFieldUpdate},
		{"ProcessActionTypeAlert", ProcessActionTypeAlert},
		{"ProcessActionTypeFlow", ProcessActionTypeFlow},
	}

	for _, pa := range processActionTypes {
		if collide, ok := automationActionTypes[pa.value]; ok {
			t.Errorf("approval %s value %q collides with automation %s: the approval side-effect and automation dispatch-mechanism taxonomies must stay separate (see docs/design/action-taxonomy.md)", pa.name, pa.value, collide)
		}
	}
}
