from __future__ import annotations

from agentlint.formatters import PROJECT_LINK, render_markdown
from agentlint.models import CheckResult


def _sample_findings() -> list[CheckResult]:
    return [
        CheckResult("secret_leak", "secret found", "error", file_path="src/a.py", line=10),
        CheckResult("todo_bombs", "todo", "warning", file_path="src/a.py", line=22),
        CheckResult("scope_drift", "scope", "warning", file_path="docs/readme.md", line=1),
    ]


def test_render_markdown_structure() -> None:
    text = render_markdown(_sample_findings())
    assert text.startswith("# agentlint Report")
    assert "| Check | Severity | Count |" in text
    assert "| `secret_leak` | `error` | 1 |" in text
    assert "| `scope_drift` | `warning` | 1 |" in text
    assert "<details><summary><code>docs/readme.md</code> (1 findings)</summary>" in text
    assert "<details><summary><code>src/a.py</code> (2 findings)</summary>" in text
    assert "`error` `secret_leak` `src/a.py:10`: secret found" in text
    assert f"Generated by [agentlint]({PROJECT_LINK})." in text


def test_render_markdown_no_findings() -> None:
    text = render_markdown([])
    assert "| `-` | `-` | 0 |" in text
    assert "No findings." in text
