package providers

import (
	"testing"
)

// expectedTier3 lists all 12 Tier 3 Specialized provider names (PROV-03).
var expectedTier3 = []string{
	"perplexity", "you", "voyage", "jina", "unstructured", "assemblyai",
	"deepgram", "elevenlabs", "stability", "runway", "midjourney", "huggingface",
}

// expectedTier4 lists all 16 Tier 4 Chinese/Regional provider names (PROV-04).
var expectedTier4 = []string{
	"deepseek", "zhipu", "moonshot", "qwen", "baidu", "bytedance",
	"01ai", "minimax", "baichuan", "stepfun", "sensetime", "iflytek",
	"tencent", "siliconflow", "360ai", "kuaishou",
}

// expectedTier5 lists all 11 Tier 5 Infrastructure/Gateway provider names (PROV-05).
var expectedTier5 = []string{
	"openrouter", "litellm", "cloudflare-ai", "vercel-ai", "portkey",
	"helicone", "martian", "kong", "bricksai", "aether", "notdiamond",
}

// expectedTier6 lists all 15 Tier 6 Emerging/Niche provider names (PROV-06).
var expectedTier6 = []string{
	"reka", "aleph-alpha", "lamini", "writer", "jasper", "typeface",
	"comet", "wandb", "langsmith", "pinecone", "weaviate", "qdrant",
	"chroma", "milvus", "neon",
}

// expectedTier7 lists all 10 Tier 7 Code/Dev Tools provider names (PROV-07).
var expectedTier7 = []string{
	"github-copilot", "cursor", "tabnine", "codeium", "sourcegraph",
	"codewhisperer", "replit-ai", "codestral", "watsonx", "oracle-ai",
}

// expectedTier8 lists all 10 Tier 8 Self-Hosted provider names (PROV-08).
var expectedTier8 = []string{
	"ollama", "vllm", "localai", "lmstudio", "llamacpp",
	"gpt4all", "text-gen-webui", "tensorrt-llm", "triton", "jan",
}

// expectedTier9 lists all 8 Tier 9 Enterprise provider names (PROV-09).
var expectedTier9 = []string{
	"salesforce-einstein", "servicenow", "sap-ai-core", "palantir",
	"databricks", "snowflake", "oracle-genai", "hpe-greenlake",
}

func TestTier3Count(t *testing.T) {
	reg, err := NewRegistry()
	if err != nil {
		t.Fatalf("NewRegistry failed: %v", err)
	}
	if got := reg.Stats().ByTier[3]; got != 12 {
		t.Errorf("Tier 3 count = %d, want 12", got)
	}
}

func TestTier4Count(t *testing.T) {
	reg, err := NewRegistry()
	if err != nil {
		t.Fatalf("NewRegistry failed: %v", err)
	}
	if got := reg.Stats().ByTier[4]; got != 16 {
		t.Errorf("Tier 4 count = %d, want 16", got)
	}
}

func TestTier5Count(t *testing.T) {
	reg, err := NewRegistry()
	if err != nil {
		t.Fatalf("NewRegistry failed: %v", err)
	}
	if got := reg.Stats().ByTier[5]; got != 11 {
		t.Errorf("Tier 5 count = %d, want 11", got)
	}
}

func TestTier6Count(t *testing.T) {
	reg, err := NewRegistry()
	if err != nil {
		t.Fatalf("NewRegistry failed: %v", err)
	}
	if got := reg.Stats().ByTier[6]; got != 15 {
		t.Errorf("Tier 6 count = %d, want 15", got)
	}
}

func TestTier7Count(t *testing.T) {
	reg, err := NewRegistry()
	if err != nil {
		t.Fatalf("NewRegistry failed: %v", err)
	}
	if got := reg.Stats().ByTier[7]; got != 10 {
		t.Errorf("Tier 7 count = %d, want 10", got)
	}
}

func TestTier8Count(t *testing.T) {
	reg, err := NewRegistry()
	if err != nil {
		t.Fatalf("NewRegistry failed: %v", err)
	}
	if got := reg.Stats().ByTier[8]; got != 10 {
		t.Errorf("Tier 8 count = %d, want 10", got)
	}
}

func TestTier9Count(t *testing.T) {
	reg, err := NewRegistry()
	if err != nil {
		t.Fatalf("NewRegistry failed: %v", err)
	}
	if got := reg.Stats().ByTier[9]; got != 8 {
		t.Errorf("Tier 9 count = %d, want 8", got)
	}
}

func TestTotalProviderCount(t *testing.T) {
	reg, err := NewRegistry()
	if err != nil {
		t.Fatalf("NewRegistry failed: %v", err)
	}
	if got := reg.Stats().Total; got != 108 {
		t.Errorf("Total provider count = %d, want 108", got)
	}
}

func TestTier39ProviderNames(t *testing.T) {
	reg, err := NewRegistry()
	if err != nil {
		t.Fatalf("NewRegistry failed: %v", err)
	}
	checks := []struct {
		tier  int
		names []string
	}{
		{3, expectedTier3},
		{4, expectedTier4},
		{5, expectedTier5},
		{6, expectedTier6},
		{7, expectedTier7},
		{8, expectedTier8},
		{9, expectedTier9},
	}
	for _, c := range checks {
		for _, name := range c.names {
			p, ok := reg.Get(name)
			if !ok {
				t.Errorf("Tier %d provider %q not found in registry", c.tier, name)
				continue
			}
			if p.Tier != c.tier {
				t.Errorf("provider %q tier = %d, want %d", name, p.Tier, c.tier)
			}
		}
	}
}
