package litigationplanner

import "testing"

// TestIsValidPrimaryParty pins the four-value vocab + NULL-equivalent
// behaviour the rule-editor's B3 validation hook depends on. Empty
// string is "no value supplied" = valid (NULL maps to empty on the
// wire). Non-empty must match one of the four canonical values.
func TestIsValidPrimaryParty(t *testing.T) {
	cases := []struct {
		in   string
		want bool
	}{
		{"", true},
		{"claimant", true},
		{"defendant", true},
		{"court", true},
		{"both", true},
		{"Claimant", false},  // case-sensitive
		{"clamant", false},   // typo
		{"applicant", false}, // not in vocab
		{"foo", false},
	}
	for _, c := range cases {
		if got := IsValidPrimaryParty(c.in); got != c.want {
			t.Errorf("IsValidPrimaryParty(%q) = %v, want %v", c.in, got, c.want)
		}
	}
}

// TestPrimaryPartiesOrder pins the canonical chip order (admin UI
// renders these as a select; reordering would break user muscle
// memory). Update both the slice + this test together if the order
// genuinely needs to change.
func TestPrimaryPartiesOrder(t *testing.T) {
	want := []string{"claimant", "defendant", "court", "both"}
	if len(PrimaryParties) != len(want) {
		t.Fatalf("PrimaryParties has %d entries, want %d", len(PrimaryParties), len(want))
	}
	for i, p := range PrimaryParties {
		if p != want[i] {
			t.Errorf("PrimaryParties[%d] = %q, want %q", i, p, want[i])
		}
	}
}

// TestIsValidAppealTarget is sibling-of: same shape, ensures the B1
// helper has the same NULL-equivalent semantic.
func TestIsValidAppealTarget(t *testing.T) {
	cases := []struct {
		in   string
		want bool
	}{
		{"", true},
		{"endentscheidung", true},
		{"kostenentscheidung", true},
		{"anordnung", true},
		{"schadensbemessung", true},
		{"bucheinsicht", true},
		{"foo", false},
		{"Endentscheidung", false}, // case-sensitive
	}
	for _, c := range cases {
		if got := IsValidAppealTarget(c.in); got != c.want {
			t.Errorf("IsValidAppealTarget(%q) = %v, want %v", c.in, got, c.want)
		}
	}
}
