package iace

import "testing"

func TestFindFramingCandidates_FlagsForeignZone(t *testing.T) {
	narrative := "Gewerbliche Geschirrspuelmaschine mit Boiler und Tank. Die Tuer ist verriegelt."
	fired := []PatternMatch{
		mkPM("HPforeign", "mechanical_hazard", "Walzen, Transportbaender, Bearbeitungszone", "Einzug", 80, nil, nil),
		mkPM("HPlocal", "thermal_hazard", "Boiler, Tank, Tuer", "Verbrennung", 80, nil, nil),
		mkPM("HPgeneric", "mechanical_hazard", "Quetschstelle, Gefahrbereich", "Quetschen", 80, nil, nil),
	}
	got := FindFramingCandidates(fired, narrative, 0.6)
	if len(got) != 1 || got[0].Pattern != "HPforeign" {
		t.Fatalf("want only HPforeign flagged, got %+v", got)
	}
	if got[0].Verdict != "foreign" {
		t.Errorf("fully-orphan zone should be 'foreign', got %s", got[0].Verdict)
	}
}

func TestFindFramingCandidates_PartialEchoIsPlausible(t *testing.T) {
	narrative := "Maschine mit Boiler und Tank."
	fired := []PatternMatch{
		mkPM("HPx", "thermal_hazard", "Boiler, Tank, Auspuffleitung", "x", 80, nil, nil),
	}
	got := FindFramingCandidates(fired, narrative, 0.3)
	if len(got) != 1 {
		t.Fatalf("want 1 candidate (1/3 orphan >= 0.3), got %d", len(got))
	}
	if got[0].Verdict != "plausible" || len(got[0].OrphanTerms) != 1 || got[0].OrphanTerms[0] != "auspuffleitung" {
		t.Errorf("want plausible + orphan [auspuffleitung], got %s %v", got[0].Verdict, got[0].OrphanTerms)
	}
}
