"""Tests for the analyzer."""

import pytest
from pr_guardian.scanner import ScanResult, Issue, IssueType
from pr_guardian.analyzer import AIConfidenceAnalyzer


def test_analyzer_generates_report():
    """Test that analyzer generates proper reports."""
    results = [
        ScanResult(
            file_path="test1.py",
            issues=[
                Issue(IssueType.HALLUCINATED_IMPORT, 1, 0, "Test", "error", ai_generated_likelihood=0.9)
            ],
            ai_confidence_score=0.8,
            metrics={},
            lines_of_code=10
        ),
        ScanResult(
            file_path="test2.py",
            issues=[],
            ai_confidence_score=0.2,
            metrics={},
            lines_of_code=20
        )
    ]
    
    analyzer = AIConfidenceAnalyzer()
    report = analyzer.analyze(results)
    
    assert report.total_files == 2
    assert report.scanned_files == 2
    assert report.avg_ai_confidence == 0.5
    assert len(report.high_risk_files) == 1
    assert report.total_issues == 1


def test_analyzer_markdown_format():
    """Test markdown report generation."""
    results = [
        ScanResult(
            file_path="risky.py",
            issues=[
                Issue(IssueType.HALLUCINATED_IMPORT, 5, 0, "Bad import", "error", ai_generated_likelihood=0.9)
            ],
            ai_confidence_score=0.85,
            metrics={},
            lines_of_code=50
        )
    ]
    
    analyzer = AIConfidenceAnalyzer()
    report = analyzer.analyze(results)
    markdown = analyzer.format_markdown(report, results)
    
    assert "PR Guardian Scan Results" in markdown
    assert "HIGH" in markdown
    assert "risky.py" in markdown
    assert "85%" in markdown
