import pytest
from krrkt.providers.anthropic_provider import AnthropicProvider
from krrkt.engine.deep_layer import DeepLayer


@pytest.mark.llm
@pytest.mark.asyncio
async def test_llm_finds_issues():
    provider = AnthropicProvider()
    layer = DeepLayer(provider=provider)
    findings = await layer.analyze(
        "Наша компания является лидером рынка и осуществляет деятельность в сфере IT.",
        already_found=[]
    )
    assert isinstance(findings, list)
    assert len(findings) > 0
    assert all(f["source"] == "deep" for f in findings)
    assert all("start" in f and "end" in f for f in findings)


@pytest.mark.llm
@pytest.mark.asyncio
async def test_llm_clean_text():
    provider = AnthropicProvider()
    layer = DeepLayer(provider=provider)
    findings = await layer.analyze(
        "Выпускаем подшипники в Санкт-Петербурге.",
        already_found=[]
    )
    assert isinstance(findings, list)
    # Clean text should have few or no findings
    serious = [f for f in findings if f.get("weight", 0) >= 80]
    assert len(serious) <= 1
