#!/usr/bin/env python3
"""
Lint check: Detect .pch (precompiled header) files in source directories.

Precompiled header files (.pch) are build artifacts that should never be
checked into the repository. They are large binary files generated by the
compiler and are platform/compiler-specific.

Scans: tests/**, src/**, examples/**
"""

from ci.util.paths import PROJECT_ROOT


SCAN_DIRS = ["tests", "src", "examples"]


def check() -> tuple[bool, list[str]]:
    """Scan for .pch files in source directories.

    Returns:
        (success, violations) - success is True if no .pch files found
    """
    violations: list[str] = []

    for dir_name in SCAN_DIRS:
        scan_dir = PROJECT_ROOT / dir_name
        if not scan_dir.exists():
            continue
        for pch_file in scan_dir.rglob("*.pch"):
            rel_path = pch_file.relative_to(PROJECT_ROOT)
            # Normalize to forward slashes for consistent output
            rel_str = str(rel_path).replace("\\", "/")
            violations.append(
                f"{rel_str}: Precompiled header file (.pch) found — "
                f"these are build artifacts and should not be in the repository. "
                f"Delete this file."
            )

    return (len(violations) == 0, violations)


def main() -> int:
    """Run .pch file checker standalone."""
    success, violations = check()
    if not success:
        print(f"Found {len(violations)} .pch file(s):")
        for v in violations:
            print(f"  {v}")
        return 1
    print("No .pch files found.")
    return 0


if __name__ == "__main__":
    import sys

    sys.exit(main())
