#!/bin/bash
# Pre-push hook for northroot-engine
# Runs comprehensive checks: tests, clippy, and validation

set -e

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

# Run clippy
echo "  ✓ Running clippy..."
if ! cargo clippy --all-targets --all-features -- -D warnings; then
    echo "❌ Clippy found issues. Fix them before pushing."
    exit 1
fi

# Run tests
echo "  ✓ Running tests..."
if ! cargo test --all-features; then
    echo "❌ Tests failed. Fix them before pushing."
    exit 1
fi

# Verify build succeeds
echo "  ✓ Verifying build..."
if ! cargo build --all-features --release; then
    echo "❌ Build failed. Fix issues before pushing."
    exit 1
fi

# Check that Cargo.toml version matches any version tags
if git describe --tags --exact-match HEAD 2>/dev/null; then
    TAG_VERSION=$(git describe --tags --exact-match HEAD | sed 's/^v//')
    CARGO_VERSION=$(grep '^version = ' Cargo.toml | cut -d'"' -f2)
    if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
        echo "❌ Tag version ($TAG_VERSION) does not match Cargo.toml version ($CARGO_VERSION)"
        exit 1
    fi
fi

echo "✅ Pre-push checks passed"
exit 0

