
import os
import django
import sys

# Setup Django environment
sys.path.append(os.getcwd())
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hotelfinder.settings')
django.setup()

from restaurant.models import Restaurant, MenuItem

try:
    honey_cafe = Restaurant.objects.filter(pk=1).first()
    if not honey_cafe:
        honey_cafe = Restaurant.objects.first()
    if not honey_cafe:
        # Create a fallback restaurant
        from users.models import User
        owner = User.objects.filter(role='RESTAURANT_OWNER').first()
        if not owner:
            owner = User.objects.create_user(username='temp_owner', password='password123', role='RESTAURANT_OWNER')
        honey_cafe = Restaurant.objects.create(
            owner=owner,
            name="Honey Cafe",
            location="Dehradun",
            address="123 Road",
            is_active=True
        )
    
    # Create Menu Items
    items = [
        {"name": "Paneer Tikka", "category": "STARTER", "price": 220, "is_vegetarian": True},
        {"name": "Chicken Biryani", "category": "BIRYANI", "price": 350, "is_vegetarian": False},
        {"name": "Gulab Jamun", "category": "DESSERT", "price": 100, "is_vegetarian": True},
    ]

    for item_data in items:
        item, created = MenuItem.objects.get_or_create(
            restaurant=honey_cafe,
            name=item_data["name"],
            defaults={
                "price": item_data["price"],
                "category": item_data["category"],
                "is_vegetarian": item_data["is_vegetarian"],
                "is_available": True
            }
        )
        if created:
            print(f"Created: {item.name}")
        else:
            print(f"Already exists: {item.name}")

except Restaurant.DoesNotExist:
    print("Restaurant ID 1 not found.")
except Exception as e:
    print(f"Error: {e}")
