#!/bin/bash
set -e

# Pre-push hook for query-engine
# Mirrors the checks in .gitea/workflows/ci.yml

echo "Running pre-push checks..."

# 1. Rust checks
echo "--- Rust: Check formatting ---"
cargo fmt --all -- --check

echo "--- Rust: Clippy ---"
cargo clippy --all-features -- -D warnings

echo "--- Rust: Check ---"
cargo check --all-features

echo "--- Rust: Test ---"
cargo test --all-features

# 2. Node.js bindings checks
if [ -d "bindings/nodejs" ]; then
    echo "--- Node.js: Test ---"
    pushd bindings/nodejs > /dev/null
    npm test
    popd > /dev/null
fi

# 3. Go bindings checks
if [ -d "bindings/go" ]; then
    echo "--- Go: Test ---"
    pushd bindings/go > /dev/null
    go test ./...
    popd > /dev/null
fi

echo "All checks passed!"
exit 0
