package harness

import "testing"

func TestNormalizeID(t *testing.T) {
	// Slice rather than a map so the intentional whitespace input
	// ("  Claude ", which exercises trimming) isn't a map key — gocritic
	// flags suspicious-whitespace keys.
	cases := []struct {
		in   string
		want ID
	}{
		{"claude", Claude},
		{"  Claude ", Claude},
		{"CODEX", Codex},
		{"weird", ID("weird")},
		{"", ID("")},
	}
	for _, c := range cases {
		if got := NormalizeID(c.in); got != c.want {
			t.Errorf("NormalizeID(%q) = %q, want %q", c.in, got, c.want)
		}
	}
}

func TestParseID(t *testing.T) {
	if id, ok := ParseID("claude"); !ok || id != Claude {
		t.Errorf("ParseID(claude) = %q,%v", id, ok)
	}
	if id, ok := ParseID(" CODEX "); !ok || id != Codex {
		t.Errorf("ParseID(CODEX) = %q,%v", id, ok)
	}
	// Unregistered harness ID: zero value, not ok.
	if id, ok := ParseID("cursor"); ok || id != "" {
		t.Errorf("ParseID(cursor) = %q,%v; want \"\",false (not registered)", id, ok)
	}
}

func TestDefaultFrom(t *testing.T) {
	if got := DefaultFrom("codex"); got != Codex {
		t.Errorf("DefaultFrom(codex) = %q", got)
	}
	if got := DefaultFrom("nope"); got != Default() {
		t.Errorf("DefaultFrom(nope) = %q, want %q", got, Default())
	}
}

func TestIDIsValidOrDefault(t *testing.T) {
	if !Claude.IsValid() {
		t.Error("Claude should be valid (registered)")
	}
	if Cursor.IsValid() {
		t.Error("Cursor not implemented yet, should be invalid")
	}
	if got := Cursor.OrDefault(); got != Default() {
		t.Errorf("Cursor.OrDefault() = %q, want %q", got, Default())
	}
	if got := Codex.OrDefault(); got != Codex {
		t.Errorf("Codex.OrDefault() = %q", got)
	}
}
