#!/usr/bin/env python3
"""Post-edit verification hook. Checks edited files for common issues."""
import sys
import os
import json

def main():
    # Read hook input from stdin
    try:
        hook_input = json.load(sys.stdin)
    except (json.JSONDecodeError, EOFError):
        hook_input = {}

    tool_name = hook_input.get("tool_name", "")
    tool_input = hook_input.get("tool_input", {})
    file_path = tool_input.get("file_path", "")

    if not file_path:
        return

    # Check 1: No writes to C: drive
    if file_path.startswith("/mnt/c/") or file_path.startswith("C:"):
        print(json.dumps({
            "decision": "block",
            "reason": "FORBIDDEN: Writing to C: drive. All work must be on E: drive."
        }))
        sys.exit(0)

    # Check 2: No SQLite imports
    if file_path.endswith(".py") and os.path.exists(file_path):
        try:
            with open(file_path, "r") as f:
                content = f.read()
            if "import sqlite3" in content or "sqlite3.connect" in content:
                print(json.dumps({
                    "decision": "warn",
                    "reason": "WARNING: SQLite detected. Use Elestio PostgreSQL instead."
                }))
                sys.exit(0)
        except Exception:
            pass

    # All checks passed
    print(json.dumps({"decision": "allow"}))

if __name__ == "__main__":
    main()
