package handlers

import (
	"testing"

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

func TestPickComponentForPattern(t *testing.T) {
	motor := uuid.New()
	hubwerk := uuid.New()
	def := uuid.New()
	parseComps := []iace.ComponentMatch{
		{NameDE: "Elektromotor (Drehstrom)", Tags: []string{"electrical", "rotating_part"}},
		{NameDE: "Hubwerk", Tags: []string{"moving_part", "crush_point"}},
	}
	compByName := map[string]uuid.UUID{
		iace.NormalizeDEPublic("Elektromotor (Drehstrom)"): motor,
		iace.NormalizeDEPublic("Hubwerk"):                  hubwerk,
	}

	tests := []struct {
		name        string
		matchedTags []string
		zone        string
		want        uuid.UUID
	}{
		{"electrical tag → motor", []string{"electrical"}, "", motor},
		{"crush tags → hubwerk", []string{"crush_point", "moving_part"}, "", hubwerk},
		{"no overlap → default", []string{"unknown_tag"}, "", def},
		{"zone fallback → hubwerk", nil, "Gefahr am Hubwerk-Bereich", hubwerk},
		{"nothing → default", nil, "", def},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got := pickComponentForPattern(tt.matchedTags, tt.zone, parseComps, compByName, def)
			if got != tt.want {
				t.Errorf("got %v, want %v", got, tt.want)
			}
		})
	}
}
