package ucca

import (
	"strings"
	"testing"
)

func TestResolveAbbreviations(t *testing.T) {
	// unambiguous -> expanded, not flagged
	tr := ResolveAbbreviations("Was ist eine TOM?")
	if !strings.Contains(tr.Expanded, "technische und organisatorische") {
		t.Errorf("TOM must be expanded, got %q", tr.Expanded)
	}
	if len(tr.Ambiguous) != 0 {
		t.Errorf("TOM must not be ambiguous, got %v", tr.Ambiguous)
	}
	// ambiguous DSE -> flagged, NOT auto-expanded (chat context must win, else FE asks)
	tr2 := ResolveAbbreviations("welche Infos in eine DSE?")
	if tr2.Expanded != "welche Infos in eine DSE?" {
		t.Errorf("DSE must NOT be auto-mapped, got %q", tr2.Expanded)
	}
	if len(tr2.Ambiguous) != 1 || tr2.Ambiguous[0].Abbreviation != "DSE" || len(tr2.Ambiguous[0].Candidates) != 2 {
		t.Errorf("DSE must be flagged ambiguous with 2 candidates, got %v", tr2.Ambiguous)
	}
	// no abbreviation -> unchanged
	if ResolveAbbreviations("Wie ist das Wetter?").Expanded != "Wie ist das Wetter?" {
		t.Errorf("query without abbreviation must be unchanged")
	}
	// substring must NOT match ("atom" contains "tom" but is not the word TOM)
	if strings.Contains(ResolveAbbreviations("Was ist ein Atom?").Expanded, "organisatorische") {
		t.Errorf("substring 'tom' in 'Atom' must not trigger expansion")
	}
}
