#!/usr/bin/env bash
# clients/python/.githooks/pre-commit
#
# Runs fast local checks before every commit:
#   1. ruff format  — fail if any staged .py files are not formatted
#   2. ruff check   — fail on lint errors
#   3. mypy         — fail on type errors in game_engine_core/
#
# Install once per clone (from the clients/python directory):
#   git config core.hooksPath clients/python/.githooks
#
# Or run manually: bash clients/python/.githooks/pre-commit

set -euo pipefail

cd "$(git rev-parse --show-toplevel)/clients/python"

# ── 1. ruff format ───────────────────────────────────────────────────────────
echo "pre-commit: ruff format --check..."
uv run ruff format --check . 2>&1 || {
  echo "❌ ruff format: files need formatting — run 'make fmt' to fix"
  exit 1
}

# ── 2. ruff lint ─────────────────────────────────────────────────────────────
echo "pre-commit: ruff check..."
uv run ruff check . 2>&1 || {
  echo "❌ ruff check failed — run 'make lint' for details"
  exit 1
}

# ── 3. mypy type check ───────────────────────────────────────────────────────
echo "pre-commit: mypy..."
uv run mypy game_engine_core/ tests/ 2>&1 || {
  echo "❌ mypy failed — run 'make type-check' for details"
  exit 1
}

echo "✅ pre-commit checks passed"
