#!/bin/bash
# MORPH-SPEC Master Pre-Commit Hook
# Runs all validation hooks in sequence

echo "╔════════════════════════════════════════════════╗"
echo "║     MORPH-SPEC PRE-COMMIT VALIDATION           ║"
echo "╚════════════════════════════════════════════════╝"
echo ""

HOOKS_DIR="$(dirname "$0")"

# Run all hooks in order
HOOKS=(
  "pre-commit-agents.sh"
  "pre-commit-costs.sh"
  "pre-commit-specs.sh"
  "pre-commit-tests.sh"
)

HAS_FAILURES=false

for hook in "${HOOKS[@]}"; do
  HOOK_PATH="$HOOKS_DIR/$hook"

  if [ ! -f "$HOOK_PATH" ]; then
    echo "⚠️  Hook not found: $hook (skipping)"
    continue
  fi

  echo "─────────────────────────────────────────────────"
  if ! bash "$HOOK_PATH"; then
    HAS_FAILURES=true
    echo "❌ Hook failed: $hook"
  fi
  echo ""
done

echo "═════════════════════════════════════════════════"

if [ "$HAS_FAILURES" = true ]; then
  echo "❌ PRE-COMMIT VALIDATION FAILED"
  echo "   Fix errors above before committing"
  echo "   Or use: git commit --no-verify to skip"
  exit 1
fi

echo "✅ ALL PRE-COMMIT VALIDATIONS PASSED"
exit 0
