#!/bin/sh
# cargo-husky pre-commit hook

set -e

echo "Running pre-commit checks..."

# Format code
echo "→ Running cargo fmt..."
cargo fmt --all

# Check for clippy warnings
echo "→ Running cargo clippy..."
cargo clippy --all-targets --all-features -- -D warnings

# Security audit
echo "→ Running cargo audit..."
if ! cargo audit --version > /dev/null 2>&1; then
    echo "⚠ cargo-audit not installed, skipping security audit"
    echo "  Install with: cargo install cargo-audit"
else
    cargo audit || echo "⚠ Security advisories found - review before release"
fi

# Dependency checks (warnings only, don't block commits)
echo "→ Running cargo deny..."
if ! cargo deny --version > /dev/null 2>&1; then
    echo "⚠ cargo-deny not installed, skipping license/advisory check"
    echo "  Install with: cargo install cargo-deny"
else
    cargo deny check 2>&1 | grep -v "^warning" || true
fi

echo "✓ All pre-commit checks passed!"
