package ucca

import "testing"

// A superseded alt-source must rank below the same result when it is NOT
// superseded (the eu-v1 norm), but only demoted — the penalty is finite, so it
// stays in the pool and remains findable for history/transition questions.
func TestAuthorityScore_SupersededIsDemotedNotRemoved(t *testing.T) {
	fresh := LegalSearchResult{
		Score: 0.65, SourceClass: "binding_law", AuthorityWeight: 100,
		Jurisdiction: "EU", RegulationShort: "CRA", Article: "13",
	}
	old := fresh
	old.Superseded = true

	sFresh := authorityScore("CRA Sicherheitsupdates Hersteller", fresh, "", false)
	sOld := authorityScore("CRA Sicherheitsupdates Hersteller", old, "", false)

	if sOld >= sFresh {
		t.Errorf("superseded must score lower: fresh=%.3f superseded=%.3f", sFresh, sOld)
	}
	gap := sFresh - sOld
	if gap < supersededPenalty-0.001 || gap > supersededPenalty+0.001 {
		t.Errorf("demotion should equal supersededPenalty (%.2f), got %.3f", supersededPenalty, gap)
	}
	// Still a positive, finite score → present in the pool, not hidden.
	if sOld <= -1 {
		t.Errorf("superseded score collapsed (%.3f) — must remain findable", sOld)
	}
}
