package audit

import (
	"testing"

	"github.com/breakpilot/ai-compliance-sdk/internal/iace"
)

func TestSuggestTagsFor_RanksSharedRequiredTags(t *testing.T) {
	byID := map[string]iace.HazardPattern{
		"P1": {ID: "P1", RequiredComponentTags: []string{"backflow_risk", "dom_warewashing"}},
		"P2": {ID: "P2", RequiredComponentTags: []string{"backflow_risk"}},
		"P3": {ID: "P3", RequiredComponentTags: []string{"sharp_edge"}},
	}
	got := suggestTagsFor([]string{"P1", "P2", "P3"}, byID)
	if len(got) == 0 || got[0] != "backflow_risk" {
		t.Fatalf("want backflow_risk ranked first (2 patterns), got %v", got)
	}
}

func TestSuggestTagsFor_TopThreeStableAlpha(t *testing.T) {
	byID := map[string]iace.HazardPattern{
		"P1": {ID: "P1", RequiredComponentTags: []string{"d", "b", "a", "c"}},
	}
	got := suggestTagsFor([]string{"P1"}, byID)
	if len(got) != 3 || got[0] != "a" || got[1] != "b" || got[2] != "c" {
		t.Fatalf("want stable alpha top-3 [a b c], got %v", got)
	}
}

func TestSuggestTagsFor_UnknownPatternIgnored(t *testing.T) {
	byID := map[string]iace.HazardPattern{}
	if got := suggestTagsFor([]string{"missing"}, byID); len(got) != 0 {
		t.Fatalf("want empty for unknown patterns, got %v", got)
	}
}
