package policy

import "testing"

func TestDetermineRoute(t *testing.T) {
	tests := []struct {
		name             string
		globalAutoAct    string
		entityAutoAct    string
		approvalRequired string
		wantRoute        string
		wantCheck        string
	}{
		{
			"global auto_act off blocks everything",
			"off", "", "none",
			"escalate", "blocked: global auto_act disabled",
		},
		{
			"global auto_act false blocks everything",
			"false", "", "none",
			"escalate", "blocked: global auto_act disabled",
		},
		{
			"per-entity kill-switch blocks",
			"on", "true", "none",
			"escalate", "blocked: per-entity kill-switch",
		},
		{
			"approval none auto-acts",
			"on", "", "none",
			"auto-act", "allowed",
		},
		{
			"approval required escalates",
			"on", "", "operator",
			"escalate", "requires approval: operator",
		},
		{
			"approval none with empty global defaults to auto-act",
			"", "", "none",
			"auto-act", "allowed",
		},
		{
			"global on, no entity kill, approval confirmation",
			"on", "", "confirmation",
			"escalate", "requires approval: confirmation",
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			route, check := determineRoute(tt.globalAutoAct, tt.entityAutoAct, tt.approvalRequired)
			if route != tt.wantRoute {
				t.Errorf("route = %q, want %q", route, tt.wantRoute)
			}
			if check != tt.wantCheck {
				t.Errorf("autonomyCheck = %q, want %q", check, tt.wantCheck)
			}
		})
	}
}
