import pytest

from app.services.ai_engine.base import EngineType


class TestAllAdaptersRegistered:
    def test_all_nine_adapters_in_adapter_classes(self):
        from app.services.ai_engine.batch_query import _ADAPTER_CLASSES

        registered_types = set(_ADAPTER_CLASSES.keys())
        expected_types = {
            EngineType.CHATGPT,
            EngineType.PERPLEXITY,
            EngineType.KIMI,
            EngineType.WENXIN,
            EngineType.DOUBAO,
            EngineType.YUANBAO,
            EngineType.DEEPSEEK,
            EngineType.QWEN,
            EngineType.GEMINI,
        }

        assert registered_types == expected_types, (
            f"Missing adapters: {expected_types - registered_types}. "
            f"Extra adapters: {registered_types - expected_types}"
        )

    def test_adapter_classes_has_nine_entries(self):
        from app.services.ai_engine.batch_query import _ADAPTER_CLASSES

        assert len(_ADAPTER_CLASSES) == 9, (
            f"Expected 9 adapters, got {len(_ADAPTER_CLASSES)}"
        )

    def test_deepseek_adapter_registered(self):
        from app.services.ai_engine.batch_query import _ADAPTER_CLASSES
        from app.services.ai_engine.deepseek import DeepSeekAdapter

        assert EngineType.DEEPSEEK in _ADAPTER_CLASSES
        assert _ADAPTER_CLASSES[EngineType.DEEPSEEK] == DeepSeekAdapter

    def test_qwen_adapter_registered(self):
        from app.services.ai_engine.batch_query import _ADAPTER_CLASSES
        from app.services.ai_engine.qwen import QwenAdapter

        assert EngineType.QWEN in _ADAPTER_CLASSES
        assert _ADAPTER_CLASSES[EngineType.QWEN] == QwenAdapter

    def test_gemini_adapter_registered(self):
        from app.services.ai_engine.batch_query import _ADAPTER_CLASSES
        from app.services.ai_engine.gemini import GeminiAdapter

        assert EngineType.GEMINI in _ADAPTER_CLASSES
        assert _ADAPTER_CLASSES[EngineType.GEMINI] == GeminiAdapter

    def test_chatgpt_adapter_registered(self):
        from app.services.ai_engine.batch_query import _ADAPTER_CLASSES
        from app.services.ai_engine.chatgpt import ChatGPTAdapter

        assert EngineType.CHATGPT in _ADAPTER_CLASSES
        assert _ADAPTER_CLASSES[EngineType.CHATGPT] == ChatGPTAdapter

    def test_perplexity_adapter_registered(self):
        from app.services.ai_engine.batch_query import _ADAPTER_CLASSES
        from app.services.ai_engine.perplexity import PerplexityAdapter

        assert EngineType.PERPLEXITY in _ADAPTER_CLASSES
        assert _ADAPTER_CLASSES[EngineType.PERPLEXITY] == PerplexityAdapter

    def test_kimi_adapter_registered(self):
        from app.services.ai_engine.batch_query import _ADAPTER_CLASSES
        from app.services.ai_engine.kimi import KimiAdapter

        assert EngineType.KIMI in _ADAPTER_CLASSES
        assert _ADAPTER_CLASSES[EngineType.KIMI] == KimiAdapter

    def test_wenxin_adapter_registered(self):
        from app.services.ai_engine.batch_query import _ADAPTER_CLASSES
        from app.services.ai_engine.wenxin import WenxinAdapter

        assert EngineType.WENXIN in _ADAPTER_CLASSES
        assert _ADAPTER_CLASSES[EngineType.WENXIN] == WenxinAdapter

    def test_doubao_adapter_registered(self):
        from app.services.ai_engine.batch_query import _ADAPTER_CLASSES
        from app.services.ai_engine.doubao import DoubaoAdapter

        assert EngineType.DOUBAO in _ADAPTER_CLASSES
        assert _ADAPTER_CLASSES[EngineType.DOUBAO] == DoubaoAdapter

    def test_yuanbao_adapter_registered(self):
        from app.services.ai_engine.batch_query import _ADAPTER_CLASSES
        from app.services.ai_engine.yuanbao import YuanbaoAdapter

        assert EngineType.YUANBAO in _ADAPTER_CLASSES
        assert _ADAPTER_CLASSES[EngineType.YUANBAO] == YuanbaoAdapter


class TestBatchServiceWithAllAdapters:
    def test_batch_service_builds_all_adapters(self):
        from app.services.ai_engine.batch_query import _build_adapters

        adapters = _build_adapters()

        expected_engines = [
            "chatgpt", "perplexity", "kimi", "wenxin", "doubao",
            "yuanbao", "deepseek", "qwen", "gemini"
        ]

        for engine in expected_engines:
            assert engine in adapters, f"Missing adapter: {engine}"

        assert len(adapters) == 9, (
            f"Expected 9 adapters built, got {len(adapters)}"
        )
