#!/usr/bin/env python3
"""
Simple test script for the Dynamic Multi-Agent Router System
"""

import requests
import json
import time

def test_agent_system():
    """Test the agent system with various requests"""
    base_url = "http://localhost:5678"
    webhook_url = f"{base_url}/webhook/agent-task"
    
    print("🧪 Testing Dynamic Multi-Agent Router System")
    print("=" * 50)
    
    # Test cases
    test_cases = [
        {
            "name": "Mobile App Development",
            "request": {
                "task": "I need help building a mobile app for food delivery",
                "context": "We're a startup with 3 developers, 6-week timeline"
            }
        },
        {
            "name": "UI Design Request",
            "request": {
                "task": "Design a modern dashboard interface for our analytics platform"
            }
        },
        {
            "name": "Backend Architecture",
            "request": {
                "task": "Design the backend architecture for a real-time chat application",
                "context": "Expected 100k concurrent users, microservices preferred"
            }
        },
        {
            "name": "Marketing Strategy",
            "request": {
                "task": "Create a social media strategy for our new app launch",
                "context": "Target audience: Gen Z, budget: $10k, timeline: 2 months"
            }
        }
    ]
    
    for i, test_case in enumerate(test_cases, 1):
        print(f"\n📋 Test {i}: {test_case['name']}")
        print(f"Request: {test_case['request']['task']}")
        
        try:
            start_time = time.time()
            response = requests.post(
                webhook_url,
                json=test_case['request'],
                headers={"Content-Type": "application/json"},
                timeout=60
            )
            end_time = time.time()
            
            if response.status_code == 200:
                data = response.json()
                if data.get('success'):
                    agents = data.get('agents_consulted', [])
                    execution_time = data.get('execution_time', 0)
                    print(f"✅ Success - Agents: {agents}, Time: {execution_time}ms")
                    
                    # Show synthesized plan preview
                    plan = data.get('synthesized_plan', '')
                    if plan:
                        lines = plan.split('\n')[:3]  # First 3 lines
                        print(f"📝 Plan preview: {' '.join(lines)}...")
                else:
                    print(f"❌ Failed - {data.get('error', 'Unknown error')}")
            else:
                print(f"❌ HTTP {response.status_code} - {response.text}")
                
        except requests.exceptions.Timeout:
            print("⏰ Request timed out")
        except Exception as e:
            print(f"❌ Error: {str(e)}")
    
    print("\n" + "=" * 50)
    print("🎉 Testing complete!")

if __name__ == "__main__":
    test_agent_system()
