#!/bin/sh
# Check for the repository toolchain.
if ! rustc --version > /dev/null 2>&1; then
    echo "Error: Pinned Rust toolchain is required but not installed."
    echo "Install with: rustup toolchain install 1.99.1"
    exit 1
fi

RUST_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.rs$' || true)
if [ -z "$RUST_FILES" ]; then
    exit 0
fi

echo "Running ./scripts/fmt.sh --check..."
if ! ./scripts/fmt.sh --check; then
    echo "Format check failed. Run: ./scripts/fmt.sh"
    exit 1
fi

echo "Running cargo clippy..."
if ! cargo clippy --all-targets -- -D warnings; then
    echo "Clippy check failed."
    exit 1
fi
