#!/usr/bin/env python3

import requests
import json

def test_restaurant_api():
    """Test restaurant API responses"""
    try:
        # Test restaurants list API
        print("Testing restaurants list API...")
        response = requests.get("http://localhost:8001/api/restaurants?per_page=3")
        
        if response.status_code == 200:
            data = response.json()
            print(f"✅ Restaurant list API works - {len(data.get('restaurants', []))} restaurants returned")
            
            if data.get('restaurants'):
                restaurant = data['restaurants'][0]
                print(f"📋 Sample restaurant:")
                print(f"  Name: {restaurant.get('name')}")
                print(f"  Image: {restaurant.get('image')}")
                print(f"  ID: {restaurant.get('id')}")
                
                # Test restaurant detail API
                print(f"\nTesting restaurant detail API for {restaurant.get('id')}...")
                detail_response = requests.get(f"http://localhost:8001/api/restaurants/{restaurant.get('id')}")
                
                if detail_response.status_code == 200:
                    detail_data = detail_response.json()
                    if detail_data.get('success'):
                        restaurant_detail = detail_data.get('restaurant', {})
                        print(f"✅ Restaurant detail API works")
                        print(f"  Name: {restaurant_detail.get('name')}")
                        if restaurant_detail.get('photos'):
                            print(f"  Photos: {len(restaurant_detail.get('photos'))} photos found")
                            for i, photo in enumerate(restaurant_detail.get('photos', [])[:3]):
                                print(f"    Photo {i+1}: {photo.get('url')} (Primary: {photo.get('is_primary')})")
                        else:
                            print("  ❌ No photos found")
                    else:
                        print(f"❌ Restaurant detail failed: {detail_data.get('message')}")
                else:
                    print(f"❌ Restaurant detail API failed: {detail_response.status_code}")
        else:
            print(f"❌ Restaurant list API failed: {response.status_code}")
            print(f"Response: {response.text}")
            
    except Exception as e:
        print(f"❌ Error testing API: {e}")

if __name__ == "__main__":
    test_restaurant_api()