echo "🚀 Running pre-push checks..."

# Run only critical tests (auth + security) — fast gate before push.
# Run `pnpm test:unit` or `pnpm test:coverage` locally for full coverage.
echo "🧪 Running critical tests (auth + security)..."
pnpm run test:critical
if [ $? -ne 0 ]; then
    echo "❌ Critical tests failed. Please fix failing tests before pushing."
    exit 1
fi

# Generate and validate OpenAPI spec to prevent breaking API contract
echo "🔧 Generating OpenAPI spec and validating..."
pnpm -s swagger:generate && pnpm -s swagger:check
if [ $? -ne 0 ]; then
    echo "❌ OpenAPI generation/validation failed. Please fix swagger issues before pushing."
    exit 1
fi

echo "✅ All pre-push checks passed!"
