import pytest
from ImportNinja.utils import (
    print_counts,
    print_syntax_error_files,
    print_unused_imports,
    print_imports
)


@pytest.fixture
def capsys_output():
    """Helper fixture to capture standard output."""
    return


def test_print_counts(capsys):
    python_files = ["file1.py", "file2.py"]
    all_imports = {"os", "sys"}
    all_imports_with_duplicates = ["os", "sys", "os"]
    all_unused_imports = {"file1.py": {"sys"}}

    print_counts(python_files, all_imports, all_imports_with_duplicates, all_unused_imports)
    captured = capsys.readouterr()

    assert "Total Python Files Scanned: 2" in captured.out
    assert "Total Import Statements: 3" in captured.out
    assert "Unique Libraries Imported: 2" in captured.out
    assert "Total Unused Imports: 1" in captured.out


def test_print_syntax_error_files_single(capsys):
    syntax_error_files = ["syntax_error.py"]
    print_syntax_error_files(syntax_error_files)
    captured = capsys.readouterr()

    assert "Syntax error in 1 file:" in captured.out
    assert "- syntax_error.py" in captured.out


def test_print_syntax_error_files_multiple(capsys):
    syntax_error_files = ["file1.py", "file2.py"]
    print_syntax_error_files(syntax_error_files)
    captured = capsys.readouterr()

    assert "Syntax error in 2 files:" in captured.out
    assert "- file1.py" in captured.out
    assert "- file2.py" in captured.out


def test_print_unused_imports(capsys):
    all_unused_imports = {
        "file1.py": {"sys"},
        "file2.py": {"os", "json"}
    }
    print_unused_imports(all_unused_imports)
    captured = capsys.readouterr()

    assert "Unused Imports:" in captured.out
    assert "- file1.py:" in captured.out
    assert "  - sys" in captured.out
    assert "- file2.py:" in captured.out
    assert "  - os" in captured.out
    assert "  - json" in captured.out


def test_print_imports(capsys):
    imports = {"os", "sys", "json"}
    print_imports(imports)
    captured = capsys.readouterr()

    assert "Dependencies:" in captured.out
    assert "- json" in captured.out
    assert "- os" in captured.out
    assert "- sys" in captured.out
