#!/usr/bin/env bash
# Pre-push hook: run local checks that match CI before allowing push.
# Install: git config core.hooksPath .githooks

set -euo pipefail

run_ci_like_checks() {
  echo ">>> pre-push: running local checks required before push"

  if ! command -v uv >/dev/null; then
    echo "[pre-push] Missing 'uv' in PATH. Install with: curl -LsSf https://astral.sh/uv/install.sh | sh" >&2
    exit 1
  fi

  echo "==> ruff check"
  uv run ruff check .

  echo "==> ruff format --check"
  uv run ruff format --check .

  echo "==> pyright"
  uv run pyright

  echo "==> gitlint (conventional commits)"
  if git rev-parse --verify --quiet origin/main >/dev/null; then
    uv run gitlint --commits "origin/main..HEAD"
  else
    echo "   skipped: origin/main not found locally (run 'git fetch origin main' to enable)"
  fi

  echo "==> pytest (non-exhaustive)"
  uv run pytest -m "not exhaustive" -x -q

  echo "==> pre-push checks passed"
}

run_ci_like_checks
