#!/bin/bash

# EXTREME TechIRCd Stress Test Runner
# This script runs progressively more brutal stress tests

echo "💀💀💀 EXTREME STRESS TEST SUITE 💀💀💀"
echo ""

# Check if TechIRCd is running
if ! pgrep -f "techircd" > /dev/null; then
    echo "🚨 TechIRCd is not running! Starting it..."
    ./techircd start &
    sleep 3
    echo "✅ TechIRCd started"
fi

echo "🔥 Available EXTREME stress tests:"
echo ""
echo "1. extreme_bomb      - 150 simultaneous connections + message flood"
echo "2. extreme_rapid     - Rapid fire connection test (original + extreme scenarios)"
echo "3. extreme_nuclear   - THE NUCLEAR OPTION (300 clients, everything at max)"
echo "4. extreme_python    - Custom Python brutality test"
echo "5. extreme_all       - ALL EXTREME TESTS IN SEQUENCE"
echo ""

if [ $# -eq 0 ]; then
    echo "Usage: $0 <test_name>"
    echo "Example: $0 extreme_bomb"
    exit 1
fi

TEST_TYPE=$1

case $TEST_TYPE in
    extreme_bomb)
        echo "💣 Running EXTREME Mass Connection Bomb..."
        python3 stress_test.py --scenario "EXTREME: Mass Connection Bomb"
        ;;
    extreme_rapid)
        echo "⚡ Running EXTREME Rapid Fire Connections..."
        python3 stress_test.py --scenario "EXTREME: Rapid Fire Connections"
        ;;
    extreme_nuclear)
        echo "☢️  Running THE NUCLEAR OPTION..."
        echo "⚠️  WARNING: This test uses 300 clients!"
        python3 stress_test.py --scenario "EXTREME: The Nuclear Option"
        ;;
    extreme_python)
        echo "🐍 Running Custom Python Brutality Test..."
        python3 extreme_stress.py
        ;;
    extreme_hurricane)
        echo "🌪️ Running EXTREME Message Hurricane..."
        python3 stress_test.py --scenario "EXTREME: Message Hurricane"
        ;;
    extreme_chaos)
        echo "🔥 Running EXTREME Connection Chaos..."
        python3 stress_test.py --scenario "EXTREME: Connection Chaos"
        ;;
    extreme_all)
        echo "💀 RUNNING ALL EXTREME TESTS IN SEQUENCE..."
        echo "⚠️  This will be BRUTAL on your server!"
        read -p "Are you sure? (yes/NO): " confirm
        if [ "$confirm" = "yes" ]; then
            echo ""
            echo "🚀 Starting extreme test sequence..."
            
            echo "1/6: Mass Connection Bomb"
            python3 stress_test.py --scenario "EXTREME: Mass Connection Bomb"
            sleep 5
            
            echo "2/6: Rapid Fire Connections" 
            python3 stress_test.py --scenario "EXTREME: Rapid Fire Connections"
            sleep 5
            
            echo "3/6: Message Hurricane"
            python3 stress_test.py --scenario "EXTREME: Message Hurricane"
            sleep 5
            
            echo "4/6: Connection Chaos"
            python3 stress_test.py --scenario "EXTREME: Connection Chaos"
            sleep 5
            
            echo "5/6: Custom Python Brutality"
            python3 extreme_stress.py
            sleep 10
            
            echo "6/6: THE NUCLEAR OPTION"
            python3 stress_test.py --scenario "EXTREME: The Nuclear Option"
            
            echo "💀 ALL EXTREME TESTS COMPLETE 💀"
        else
            echo "❌ Extreme test sequence cancelled"
        fi
        ;;
    *)
        echo "❌ Unknown test type: $TEST_TYPE"
        echo "Available: extreme_bomb, extreme_rapid, extreme_nuclear, extreme_python, extreme_hurricane, extreme_chaos, extreme_all"
        exit 1
        ;;
esac

echo ""
echo "🏁 Stress test complete!"
echo "Check server logs for performance data"
