package models

import (
	"testing"
)

func TestModelRegistry_FindModel_Exact(t *testing.T) {
	r := &ModelRegistry{
		Providers: map[string]ProviderInfo{
			"openai": {
				Models: map[string]ModelMetadata{
					"gpt-4o": {ID: "gpt-4o", Name: "GPT-4o"},
				},
			},
		},
	}
	m := r.FindModel("gpt-4o")
	if m == nil {
		t.Fatal("expected to find gpt-4o")
	}
	if m.Name != "GPT-4o" {
		t.Fatalf("expected GPT-4o, got %s", m.Name)
	}
}

func TestModelRegistry_FindModel_Fuzzy(t *testing.T) {
	r := &ModelRegistry{
		Providers: map[string]ProviderInfo{
			"openai": {
				Models: map[string]ModelMetadata{
					"gpt-4o": {ID: "gpt-4o", Name: "GPT-4o"},
				},
			},
		},
	}
	// Fuzzy: "gpt-4o-2024-05-13" should match "gpt-4o"
	m := r.FindModel("gpt-4o-2024-05-13")
	if m == nil {
		t.Fatal("expected fuzzy match")
	}
	if m.Name != "GPT-4o" {
		t.Fatalf("expected GPT-4o, got %s", m.Name)
	}
}

func TestModelRegistry_FindModel_NotFound(t *testing.T) {
	r := &ModelRegistry{
		Providers: map[string]ProviderInfo{
			"openai": {
				Models: map[string]ModelMetadata{
					"gpt-4o": {ID: "gpt-4o", Name: "GPT-4o"},
				},
			},
		},
	}
	m := r.FindModel("nonexistent-model")
	if m != nil {
		t.Fatal("expected nil for nonexistent model")
	}
}

func TestModelRegistry_FindModel_ReverseFuzzy(t *testing.T) {
	r := &ModelRegistry{
		Providers: map[string]ProviderInfo{
			"openai": {
				Models: map[string]ModelMetadata{
					"gpt-5.4-mini-2026-04-01": {ID: "gpt-5.4-mini-2026-04-01", Name: "GPT-5.4 Mini"},
				},
			},
		},
	}
	// Reverse fuzzy: "gpt-5.4-mini" should match "gpt-5.4-mini-2026-04-01"
	m := r.FindModel("gpt-5.4-mini")
	if m == nil {
		t.Fatal("expected reverse fuzzy match")
	}
	if m.Name != "GPT-5.4 Mini" {
		t.Fatalf("expected GPT-5.4 Mini, got %s", m.Name)
	}
}
