#!/bin/bash
# Local validation script - runs the same checks as GitHub Actions CI
# Run this before committing to catch issues early

set -e  # Exit on first error

# Change to project root (parent of scripts directory)
cd "$(dirname "$0")/.."

echo "🔍 Running local validation checks..."
echo ""

# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# Function to print status
print_status() {
    if [ $? -eq 0 ]; then
        echo -e "${GREEN}✓${NC} $1"
    else
        echo -e "${RED}✗${NC} $1"
        exit 1
    fi
}

# 1. Auto-format and check
echo -e "${YELLOW}[1/4]${NC} Formatting code..."
cargo fmt --all
print_status "Code formatting"
echo ""

# 2. Run Clippy
echo -e "${YELLOW}[2/4]${NC} Running Clippy lints..."
cargo clippy --all-targets --all-features -- -D warnings
print_status "Clippy checks"
echo ""

# 3. Run tests
echo -e "${YELLOW}[3/4]${NC} Running tests..."
cargo test --verbose
print_status "Tests"
echo ""

# 4. Build release
echo -e "${YELLOW}[4/4]${NC} Building release binary..."
cargo build --release --verbose
print_status "Release build"
echo ""

echo -e "${GREEN}✨ All validation checks passed!${NC}"
echo "Your code is ready to commit and push."
