#!/usr/bin/env python3
"""
Test script to verify domain recommendations are working properly
"""

import requests
import json

def test_domain_recommendations():
    """Test recommendations for different domains"""
    
    base_url = "http://localhost:8002"
    
    # Test domains
    test_domains = [
        "saas",
        "SaaS",  # Test case sensitivity
        "ecommerce",
        "E-commerce",  # Test case sensitivity and hyphen
        "healthcare",
        "finance",
        "gaming",
        "education",
        "media",
        "iot",
        "social",
        "elearning",
        "realestate",
        "travel",
        "manufacturing",
        "personal",
        "startup",
        "enterprise"
    ]
    
    print("🧪 Testing Domain Recommendations")
    print("=" * 50)
    
    for domain in test_domains:
        print(f"\n🔍 Testing domain: '{domain}'")
        
        # Test recommendation endpoint
        payload = {
            "domain": domain,
            "budget": 900.0
        }
        
        try:
            response = requests.post(f"{base_url}/recommend/best", json=payload, timeout=10)
            
            if response.status_code == 200:
                data = response.json()
                recommendations = data.get('recommendations', [])
                
                print(f"  ✅ Status: {response.status_code}")
                print(f"  📝 Response: {recommendations}")
                print(f"  📊 Recommendations: {len(recommendations)}")
                
                if recommendations:
                    print(f"  🏆 Top recommendation: {recommendations[0]['stack_name']}")
                    print(f"  💰 Cost: ${recommendations[0]['monthly_cost']}")
                    print(f"  🎯 Domains: {recommendations[0].get('recommended_domains', 'N/A')}")
                else:
                    print("  ⚠️  No recommendations found")
            else:
                print(f"  ❌ Error: {response.status_code}")
                print(f"  📝 Response: {response.text}")
                
        except requests.exceptions.RequestException as e:
            print(f"  ❌ Request failed: {e}")
        except Exception as e:
            print(f"  ❌ Unexpected error: {e}")
    
    # Test available domains endpoint
    print(f"\n🌐 Testing available domains endpoint")
    try:
        response = requests.get(f"{base_url}/api/domains", timeout=10)
        if response.status_code == 200:
            data = response.json()
            domains = data.get('domains', [])
            print(f"  ✅ Available domains: {len(domains)}")
            for domain in domains:
                print(f"    - {domain['domain_name']} ({domain['project_scale']}, {domain['team_experience_level']})")
        else:
            print(f"  ❌ Error: {response.status_code}")
    except Exception as e:
        print(f"  ❌ Error: {e}")

if __name__ == "__main__":
    test_domain_recommendations()
