#!/bin/bash

echo "🧪 Testing 10 Concurrent Voice Calls"
echo "===================================="
echo ""

# Test by creating 10 connection requests simultaneously
echo "Creating 10 simultaneous connection requests..."
echo ""

for i in {1..10}; do
  (
    echo "[$i] Requesting connection details..."
    response=$(curl -s -X POST https://app2.syntheon.in/voicebot/api/connection-details \
      -H "Content-Type: application/json" \
      -d '{"room_config":{"agents":[{"agent_name":"default"}]},"agent_config":{"first_message":"Test call '$i'"}}')
    
    if echo "$response" | grep -q "serverUrl"; then
      room_name=$(echo "$response" | grep -o '"roomName":"[^"]*"' | cut -d'"' -f4)
      echo "[$i] ✓ Connection details received - Room: $room_name"
    else
      echo "[$i] ✗ Failed to get connection details"
    fi
  ) &
done

# Wait for all background jobs to complete
wait

echo ""
echo "✓ All 10 requests completed"
echo ""
echo "Check backend logs to see if all 10 agents joined:"
echo "  cd /var/www/html/livekit_frontend/BackEnd/agent-starter-python"
echo "  tail -100 backend-10workers.log | grep 'Job received'"
