import pytest
from app.core.providers.factory import get_llm_provider, get_tts_provider, get_stt_provider
from app.core.providers.llm.general import GeneralProvider
from app.core.providers.tts.gemini import GeminiTTSProvider
from app.core.providers.stt.gemini import GoogleSTTProvider

# --- Existing Tests for LLM Provider ---

def test_get_llm_provider_returns_deepseek_provider():
    """Tests that the factory returns a GeneralProvider instance for 'deepseek'."""
    provider = get_llm_provider("deepseek")
    assert isinstance(provider, GeneralProvider)

def test_get_llm_provider_returns_gemini_provider():
    """Tests that the factory returns a GeneralProvider instance for 'gemini'."""
    provider = get_llm_provider("gemini")
    assert isinstance(provider, GeneralProvider)

def test_get_llm_provider_raises_error_for_unsupported_provider():
    """Tests that the factory raises an error for an unknown provider with no model name."""
    with pytest.raises(ValueError, match="No model name provided for 'unknown'"):
        get_llm_provider("unknown")


# --- NEW Tests for TTS Provider ---

def test_get_tts_provider_returns_gemini_tts_provider():
    """Tests that the factory returns a GeminiTTSProvider instance for 'google_gemini'."""
    valid_voice = GeminiTTSProvider.AVAILABLE_VOICES[0]
    provider = get_tts_provider(
        "google_gemini",
        api_key="dummy_key",
        model_name="dummy-model",
        voice_name=valid_voice
    )
    assert isinstance(provider, GeminiTTSProvider)
    assert provider.api_key == "dummy_key"
    assert provider.voice_name == valid_voice

def test_get_tts_provider_falls_back_to_general():
    """Tests that the factory falls back to GeneralTTSProvider for unknown names."""
    from app.core.providers.tts.general import GeneralTTSProvider
    valid_voice = GeminiTTSProvider.AVAILABLE_VOICES[0]
    provider = get_tts_provider(
        "unknown",
        api_key="dummy_key",
        model_name="dummy-model",
        voice_name=valid_voice
    )
    assert isinstance(provider, GeneralTTSProvider)


# --- NEW Tests for STT Provider ---

def test_get_stt_provider_returns_google_stt_provider():
    """Tests that the factory returns a GoogleSTTProvider instance for 'google_gemini'."""
    provider = get_stt_provider(
        "google_gemini",
        api_key="dummy_key",
        model_name="dummy-model"
    )
    assert isinstance(provider, GoogleSTTProvider)
    assert provider.api_key == "dummy_key"
    assert provider.model_name == "dummy-model"

def test_get_stt_provider_falls_back_to_general():
    """Tests that the factory falls back to GeneralSTTProvider for unknown names."""
    from app.core.providers.stt.general import GeneralSTTProvider
    provider = get_stt_provider(
        "unknown",
        api_key="dummy_key",
        model_name="dummy-model"
    )
    assert isinstance(provider, GeneralSTTProvider)
