"""Tests for model registry."""

from __future__ import annotations

import pytest


@pytest.mark.unit
class TestModelRegistry:
    def test_get_model_by_name(self) -> None:
        from llmhosts.models.registry import get_model

        model = get_model("qwen2.5:7b")
        assert model is not None
        assert model["repo"].startswith("Qwen/")
        assert model["file"].endswith(".gguf")
        assert model["min_vram_gb"] > 0

    def test_unknown_model_returns_none(self) -> None:
        from llmhosts.models.registry import get_model

        assert get_model("nonexistent:model") is None

    def test_list_models(self) -> None:
        from llmhosts.models.registry import list_models

        models = list_models()
        assert len(models) >= 5
        assert "qwen2.5:0.5b" in models
        assert "qwen2.5:7b" in models

    def test_recommend_for_vram(self) -> None:
        from llmhosts.models.registry import recommend_for_vram

        model = recommend_for_vram(8192)
        assert model is not None
        assert model["min_vram_gb"] <= 8

    def test_recommend_for_low_vram(self) -> None:
        from llmhosts.models.registry import recommend_for_vram

        model = recommend_for_vram(1024)
        assert model is not None
        assert model["min_vram_gb"] <= 1

    def test_recommend_for_cpu_only(self) -> None:
        from llmhosts.models.registry import recommend_for_vram

        model = recommend_for_vram(0)
        assert model is not None

    def test_model_has_required_fields(self) -> None:
        from llmhosts.models.registry import get_model

        model = get_model("qwen2.5:7b")
        for field in ["repo", "file", "tokenizer_repo", "size_gb", "min_vram_gb", "architecture"]:
            assert field in model, f"Missing field: {field}"

    def test_model_path(self) -> None:
        from llmhosts.models.registry import model_path

        path = model_path("qwen2.5:7b")
        assert ".llmhosts" in path or "llmhosts" in path.lower()
        assert path.endswith(".gguf")
