#!/usr/bin/env python3
"""Pre-push hook: runs lint and type checks before allowing push."""

import subprocess
import sys


def main() -> int:
    checks = [
        (["ruff", "check", "."], "lint"),
        (["ruff", "format", "--check", "."], "format"),
    ]

    failed = False
    for cmd, name in checks:
        result = subprocess.run(cmd, capture_output=True, text=True)
        if result.returncode != 0:
            print(f"✗ {name} check failed")
            if result.stdout:
                print(result.stdout)
            failed = True

    if failed:
        print("Push aborted. Fix the above issues before pushing.")
        return 1

    print("✓ All checks passed")
    return 0


if __name__ == "__main__":
    sys.exit(main())