package usecase

import (
	"testing"

	"apps/backend/internal/module/radar/domain"
)

func TestOpportunityAccuracyPrecisionAtTenAndHighEvidenceGate(t *testing.T) {
	cases := loadAccuracyCases(t)
	if len(cases) < 10 {
		t.Fatal("accuracy fixture must contain ten cases")
	}
	truePositive, highWithoutEvidence, providerInHigh := 0, 0, 0
	for _, item := range cases[:10] {
		candidate := &domain.CandidatePost{ExternalID: "https://threads.net/post/" + item.ID, Text: item.Text}
		filtered, stats := PrefilterCandidates([]*domain.CandidatePost{candidate}, &domain.RadarWatch{Terms: item.ProductTerms}, nil)
		predictedRelevant := len(filtered) > 0 && stats.Rejected == 0
		if predictedRelevant && item.ExpectedDemand {
			truePositive++
		}
		if predictedRelevant && !item.ExpectedDemand {
			providerInHigh++
		}
		if predictedRelevant && item.ExpectedDemand && len(item.ProductTerms) == 0 {
			highWithoutEvidence++
		}
	}
	precision := float64(truePositive) / 10
	if precision < 0.8 || highWithoutEvidence != 0 || providerInHigh != 0 {
		t.Fatalf("precision gate failed: precision_at_10=%.2f high_without_evidence=%d provider_in_high=%d", precision, highWithoutEvidence, providerInHigh)
	}
}
