#!/bin/bash
# Quick status check for Redis optimization
# Usage: ./scripts/check-redis-status.sh

echo "🔍 Redis Optimization Status Check"
echo ""

# Check if AI worker is disabled
echo "1. AI Worker Status:"
if grep -q "ENABLE_AI_WORKER=false" apps/api/.env 2>/dev/null; then
    echo "   ✅ DISABLED (Good for dev)"
elif grep -q "ENABLE_AI_WORKER=true" apps/api/.env 2>/dev/null; then
    echo "   ⚠️  ENABLED (Will consume more Redis)"
else
    echo "   ⚠️  NOT SET (will default to enabled)"
    echo "      → Add ENABLE_AI_WORKER=false to apps/api/.env"
fi

echo ""
echo "2. Queue Status (if server is running):"
if curl -s http://localhost:3001/api/ai/queue/status 2>/dev/null | jq . 2>/dev/null; then
    echo "   ✅ Server is running"
else
    echo "   ℹ️  Server not running or endpoint not available"
fi

echo ""
echo "3. Configuration Files:"
if [ -f "apps/api/.env" ]; then
    echo "   ✅ apps/api/.env exists"
else
    echo "   ❌ apps/api/.env missing"
fi

if [ -f "apps/api/scripts/redis-monitor.ts" ]; then
    echo "   ✅ redis-monitor.ts created"
else
    echo "   ❌ redis-monitor.ts missing"
fi

if [ -f "docs/REDIS_OPTIMIZATION_GUIDE.md" ]; then
    echo "   ✅ Optimization guide created"
else
    echo "   ❌ Optimization guide missing"
fi

echo ""
echo "4. Expected Behavior:"
echo "   • Commands/sec should be < 0.2 (vs ~0.5 before)"
echo "   • Queue jobs should be empty or minimal"
echo "   • Server logs should show 'AI Worker DISABLED'"

echo ""
echo "💡 Next Steps:"
echo "   → Monitor: pnpm --filter '@my-roadtrip/api' tsx scripts/redis-monitor.ts"
echo "   → Cleanup: ./scripts/cleanup-redis.sh"
echo "   → Docs: cat REDIS_EMERGENCY_FIX.md"
