#!/usr/bin/env python3

import requests
import json

def test_restaurant_detail_api():
    """Test restaurant detail API with menu items and categories"""
    
    print("🔍 Testing restaurant detail API with menu data...")
    try:
        # Get first restaurant
        response = requests.get("http://localhost:8001/api/restaurants?per_page=1")
        if response.status_code == 200:
            data = response.json()
            if data.get('restaurants') and len(data['restaurants']) > 0:
                restaurant_id = data['restaurants'][0]['id']
                restaurant_name = data['restaurants'][0]['name']
                
                print(f"📋 Testing restaurant: {restaurant_name}")
                print(f"🆔 Restaurant ID: {restaurant_id}")
                
                # Test detailed restaurant API
                detail_response = requests.get(f"http://localhost:8001/api/restaurants/{restaurant_id}")
                
                if detail_response.status_code == 200:
                    detail_data = detail_response.json()
                    if detail_data.get('success'):
                        restaurant = detail_data.get('restaurant', {})
                        
                        print(f"✅ Restaurant detail API works")
                        print(f"📍 Name: {restaurant.get('name')}")
                        print(f"🍽️ Cuisine: {restaurant.get('cuisine_type')}")
                        
                        # Check photos
                        photos = restaurant.get('photos', [])
                        print(f"📸 Photos: {len(photos)} found")
                        if photos:
                            print(f"   Sample photo: {photos[0].get('url')}")
                        
                        # Check categories
                        categories = restaurant.get('categories', [])
                        print(f"📂 Categories: {len(categories)} found")
                        for cat in categories[:3]:  # Show first 3
                            print(f"   - {cat.get('name')}: {cat.get('description', 'No description')}")
                        
                        # Check menu items
                        menu_items = restaurant.get('menu_items', [])
                        print(f"🍽️ Menu Items: {len(menu_items)} found")
                        for item in menu_items[:5]:  # Show first 5
                            print(f"   - {item.get('name')}: {item.get('currency_code', '€')}{item.get('price', 0):.2f}")
                            if item.get('category_name'):
                                print(f"     Category: {item.get('category_name')}")
                            if item.get('is_vegetarian'):
                                print(f"     🌱 Vegetarian")
                            if item.get('is_vegan'):
                                print(f"     🌿 Vegan")
                        
                        print(f"\n📊 Summary:")
                        print(f"   ✅ Restaurant detail: Working")
                        print(f"   ✅ Photos: {len(photos)} photos")
                        print(f"   ✅ Categories: {len(categories)} categories")
                        print(f"   ✅ Menu items: {len(menu_items)} items")
                        
                    else:
                        print(f"❌ Restaurant detail failed: {detail_data.get('message')}")
                else:
                    print(f"❌ Restaurant detail API failed: {detail_response.status_code}")
                    print(f"Response: {detail_response.text}")
            else:
                print("❌ No restaurants found")
        else:
            print(f"❌ Restaurant list API failed: {response.status_code}")
            
    except Exception as e:
        print(f"❌ Error testing API: {e}")

if __name__ == "__main__":
    test_restaurant_detail_api()