#!/bin/bash
# Benchmark Runner Script
# Automatically activates virtual environment and runs benchmarks

echo "🚀 8fs Benchmark Runner"
echo "======================"

# Check if virtual environment exists
if [ ! -d "benchmark_env" ]; then
    echo "❌ Virtual environment not found. Creating one..."
    python3 -m venv benchmark_env
    source benchmark_env/bin/activate
    pip install requests numpy
    echo "✅ Virtual environment created and dependencies installed"
else
    echo "✅ Virtual environment found"
fi

# Activate virtual environment
source benchmark_env/bin/activate
echo "🔄 Virtual environment activated"

# Check if 8fs server is running
if ! curl -s http://localhost:8080/healthz > /dev/null 2>&1; then
    echo "❌ 8fs server is not running!"
    echo "💡 Please start the 8fs server first:"
    echo "   cd /Users/melihbirim/code/8fs && ./bin/8fs"
    exit 1
fi

echo "✅ 8fs server is running"

# Check if Ollama is running
if ! curl -s http://localhost:11434/api/version > /dev/null 2>&1; then
    echo "❌ Ollama is not running!"
    echo "💡 Please start Ollama first:"
    echo "   ollama serve"
    exit 1
fi

echo "✅ Ollama is running"

# Run the benchmark
echo ""
echo "🎯 Running benchmark comparison..."
echo "=================================="

cd scripts/benchmarks
python3 complete_benchmark.py

echo ""
echo "📊 Benchmark completed! Check the results above."
echo "📄 Detailed results are saved in the results/ directory."