# tests/core/test_voice_slot.py
import pytest
from core.protocol import IncomingMessage, Attachment, OutgoingMessage
from core.handlers.message import handle_message
from core.store import InMemoryStore
from core.auth import AuthManager
from core.chat import ChatManager
from core.settings import SettingsManager
from sdk.mock import MockPlatformClient


@pytest.fixture
def deps():
    platform = MockPlatformClient()
    store = InMemoryStore()
    auth_mgr = AuthManager(platform, store)
    return dict(
        platform=platform,
        chat_mgr=ChatManager(platform, store),
        auth_mgr=auth_mgr,
        settings_mgr=SettingsManager(platform, store),
    )


async def test_voice_message_returns_stub(deps):
    await deps["auth_mgr"].confirm("u1")
    msg = IncomingMessage(
        user_id="u1", platform="telegram", chat_id="C1", text="",
        attachments=[Attachment(type="audio", filename="voice.ogg")],
    )
    result = await handle_message(event=msg, **deps)
    assert len(result) == 1
    assert isinstance(result[0], OutgoingMessage)
    assert "голосов" in result[0].text.lower()


async def test_text_message_calls_platform(deps):
    await deps["auth_mgr"].confirm("u1")
    msg = IncomingMessage(user_id="u1", platform="telegram", chat_id="C1", text="Привет!")
    result = await handle_message(event=msg, **deps)
    texts = [r.text for r in result if isinstance(r, OutgoingMessage)]
    assert any("[MOCK]" in t for t in texts)


async def test_unauthenticated_user_gets_start_prompt(deps):
    msg = IncomingMessage(user_id="new_user", platform="telegram", chat_id="C1", text="hello")
    result = await handle_message(event=msg, **deps)
    assert len(result) == 1
    assert "/start" in result[0].text
