"""
Seed script — populate the database with realistic sample data for LesReseauxMeuble.
Run with:  python manage.py shell < seed_data.py
"""
import os, django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
django.setup()

from datetime import date, time, timedelta
from decimal import Decimal
from django.contrib.auth import get_user_model

User = get_user_model()

# ═══════════════════════════════════════════════════════════════
# 1. USERS
# ═══════════════════════════════════════════════════════════════
print("Creating users...")

hosts_data = [
    {"username": "aminata", "first_name": "Aminata", "last_name": "Diallo",   "email": "aminata@example.com",  "role": "host", "phone_number": "+22501010101", "country_code": "CI", "biography": "Hôte passionnée à Abidjan, je propose des logements modernes et confortables."},
    {"username": "koffi",   "first_name": "Koffi",   "last_name": "Kouadio",  "email": "koffi@example.com",    "role": "host", "phone_number": "+22901020304", "country_code": "BJ", "biography": "Propriétaire de plusieurs appartements meublés à Cotonou."},
    {"username": "fatou",   "first_name": "Fatou",    "last_name": "Sow",      "email": "fatou@example.com",    "role": "host", "phone_number": "+22176543210", "country_code": "SN", "biography": "Super-hôte à Dakar avec 5 ans d'expérience."},
]

travelers_data = [
    {"username": "jean",    "first_name": "Jean",     "last_name": "Mensah",   "email": "jean@example.com",     "role": "traveler", "phone_number": "+22801112233", "country_code": "TG"},
    {"username": "marie",   "first_name": "Marie",    "last_name": "Adjovi",   "email": "marie@example.com",    "role": "traveler", "phone_number": "+22901445566", "country_code": "BJ"},
    {"username": "oumar",   "first_name": "Oumar",    "last_name": "Ba",       "email": "oumar@example.com",    "role": "traveler", "phone_number": "+22177889900", "country_code": "SN"},
]

hosts = []
for data in hosts_data:
    user, created = User.objects.get_or_create(username=data["username"], defaults=data)
    if created:
        user.set_password("TestPass123!")
        user.kyc_status = "approved"
        user.otp_verified = True
        user.save()
    hosts.append(user)

travelers = []
for data in travelers_data:
    user, created = User.objects.get_or_create(username=data["username"], defaults=data)
    if created:
        user.set_password("TestPass123!")
        user.otp_verified = True
        user.save()
    travelers.append(user)

# Make Fatou a superhost
fatou = hosts[2]
fatou.is_superhost = True
fatou.save(update_fields=["is_superhost"])

print(f"  {len(hosts)} hôtes, {len(travelers)} voyageurs")

# ═══════════════════════════════════════════════════════════════
# 2. LISTINGS
# ═══════════════════════════════════════════════════════════════
from apps.listings.models import Listing, ListingImage, Amenity, NeighborhoodPlace

print("Creating listings...")

listings_data = [
    # ── Cotonou (Bénin) ──
    {
        "host": hosts[1], "title": "Appartement moderne à Cotonou – Haie Vive",
        "description": "Bel appartement meublé de 2 chambres avec vue sur la lagune. Climatisation, WiFi haut débit, cuisine équipée. À 5 min du marché Dantokpa.",
        "city": "Cotonou", "country": "Bénin", "address": "Quartier Haie Vive, Cotonou",
        "latitude": Decimal("6.3654"), "longitude": Decimal("2.4183"),
        "listing_type": "short_stay", "price_per_night": Decimal("25000"),
        "price_per_week": Decimal("150000"), "price_per_month": Decimal("500000"),
        "bedrooms": 2, "bathrooms": 1, "beds_count": 2, "max_guests": 4,
        "cleaning_fee": Decimal("5000"), "security_deposit": Decimal("50000"),
        "cancellation_policy": "moderate", "instant_book": True,
        "check_in_time": time(14, 0), "check_out_time": time(11, 0),
        "house_rules": "Pas de fête. Pas de fumée à l'intérieur.",
    },
    {
        "host": hosts[1], "title": "Studio cosy Fidjrossè – proche plage",
        "description": "Studio entièrement meublé à Fidjrossè, à 200m de la plage. Idéal pour voyageur solo ou couple. Parking gratuit.",
        "city": "Cotonou", "country": "Bénin", "address": "Fidjrossè Plage, Cotonou",
        "latitude": Decimal("6.3438"), "longitude": Decimal("2.3587"),
        "listing_type": "short_stay", "price_per_night": Decimal("15000"),
        "bedrooms": 1, "bathrooms": 1, "beds_count": 1, "max_guests": 2,
        "cleaning_fee": Decimal("3000"), "security_deposit": Decimal("25000"),
        "cancellation_policy": "flexible", "instant_book": True,
        "check_in_time": time(13, 0), "check_out_time": time(12, 0),
    },
    {
        "host": hosts[1], "title": "Villa 4 chambres avec piscine – Cotonou",
        "description": "Grande villa avec piscine privée, jardin tropical, 4 chambres climatisées. Parfait pour familles ou événements.",
        "city": "Cotonou", "country": "Bénin", "address": "Les Cocotiers, Cotonou",
        "latitude": Decimal("6.3725"), "longitude": Decimal("2.3900"),
        "listing_type": "short_stay", "price_per_night": Decimal("75000"),
        "price_per_week": Decimal("450000"), "price_per_month": Decimal("1500000"),
        "bedrooms": 4, "bathrooms": 3, "beds_count": 5, "max_guests": 8,
        "cleaning_fee": Decimal("15000"), "security_deposit": Decimal("150000"),
        "cancellation_policy": "strict", "pets_allowed": True,
        "check_in_time": time(15, 0), "check_out_time": time(11, 0),
        "house_rules": "Respect du voisinage. Piscine fermée après 22h.",
    },

    # ── Abidjan (Côte d'Ivoire) ──
    {
        "host": hosts[0], "title": "Loft design à Cocody – Riviera Golf",
        "description": "Loft contemporain au cœur de Cocody Riviera Golf. Décoration soignée, smart TV, WiFi fibre. Proche restaurants et centres commerciaux.",
        "city": "Abidjan", "country": "Côte d'Ivoire", "address": "Riviera Golf, Cocody, Abidjan",
        "latitude": Decimal("5.3553"), "longitude": Decimal("-3.9811"),
        "listing_type": "short_stay", "price_per_night": Decimal("35000"),
        "price_per_week": Decimal("210000"), "price_per_month": Decimal("700000"),
        "bedrooms": 1, "bathrooms": 1, "beds_count": 1, "max_guests": 2,
        "cleaning_fee": Decimal("5000"), "security_deposit": Decimal("50000"),
        "cancellation_policy": "moderate", "instant_book": True,
        "check_in_time": time(14, 0), "check_out_time": time(11, 0),
    },
    {
        "host": hosts[0], "title": "Appartement familial Marcory – 3 chambres",
        "description": "Grand appartement de 3 chambres en zone résidentielle calme. Balcon spacieux, gardien 24h/24, générateur de secours.",
        "city": "Abidjan", "country": "Côte d'Ivoire", "address": "Zone 4, Marcory, Abidjan",
        "latitude": Decimal("5.3080"), "longitude": Decimal("-3.9870"),
        "listing_type": "short_stay", "price_per_night": Decimal("45000"),
        "price_per_month": Decimal("900000"),
        "bedrooms": 3, "bathrooms": 2, "beds_count": 4, "max_guests": 6,
        "cleaning_fee": Decimal("8000"), "security_deposit": Decimal("100000"),
        "cancellation_policy": "moderate",
        "check_in_time": time(14, 0), "check_out_time": time(12, 0),
    },
    {
        "host": hosts[0], "title": "Penthouse vue lagune – Plateau Abidjan",
        "description": "Penthouse de luxe avec terrasse panoramique sur la lagune Ébrié. 2 chambres, jacuzzi, conciergerie. Proche quartier d'affaires.",
        "city": "Abidjan", "country": "Côte d'Ivoire", "address": "Le Plateau, Abidjan",
        "latitude": Decimal("5.3200"), "longitude": Decimal("-4.0167"),
        "listing_type": "short_stay", "price_per_night": Decimal("120000"),
        "price_per_month": Decimal("2500000"),
        "bedrooms": 2, "bathrooms": 2, "beds_count": 2, "max_guests": 4,
        "cleaning_fee": Decimal("20000"), "security_deposit": Decimal("200000"),
        "cancellation_policy": "strict", "instant_book": False,
        "check_in_time": time(15, 0), "check_out_time": time(11, 0),
        "house_rules": "Pas de fête. Tenue correcte dans les parties communes.",
    },

    # ── Dakar (Sénégal) ──
    {
        "host": hosts[2], "title": "Maison de charme – Ngor, Dakar",
        "description": "Maison traditionnelle rénovée à Ngor, à 300m de la plage. 3 chambres, terrasse ombragée avec vue sur l'île de Ngor.",
        "city": "Dakar", "country": "Sénégal", "address": "Ngor, Dakar",
        "latitude": Decimal("14.7485"), "longitude": Decimal("-17.5150"),
        "listing_type": "short_stay", "price_per_night": Decimal("40000"),
        "price_per_week": Decimal("240000"),
        "bedrooms": 3, "bathrooms": 2, "beds_count": 4, "max_guests": 6,
        "cleaning_fee": Decimal("7000"), "security_deposit": Decimal("80000"),
        "cancellation_policy": "flexible", "pets_allowed": True,
        "check_in_time": time(14, 0), "check_out_time": time(11, 0),
        "is_superhost_flag": True,
    },
    {
        "host": hosts[2], "title": "Studio Almadies – vue océan",
        "description": "Petit studio lumineux aux Almadies avec balcon vue mer. WiFi, climatisation, machine à laver. Quartier sûr et animé.",
        "city": "Dakar", "country": "Sénégal", "address": "Les Almadies, Dakar",
        "latitude": Decimal("14.7350"), "longitude": Decimal("-17.5050"),
        "listing_type": "short_stay", "price_per_night": Decimal("22000"),
        "bedrooms": 1, "bathrooms": 1, "beds_count": 1, "max_guests": 2,
        "cleaning_fee": Decimal("4000"), "security_deposit": Decimal("30000"),
        "cancellation_policy": "moderate", "instant_book": True,
        "check_in_time": time(13, 0), "check_out_time": time(12, 0),
        "is_superhost_flag": True,
    },

    # ── Lomé (Togo) ──
    {
        "host": hosts[1], "title": "Appart'hôtel Lomé centre – Bè Plage",
        "description": "Appartement hôtelier tout confort près de la plage de Lomé. Service de ménage quotidien, petit-déjeuner en option.",
        "city": "Lomé", "country": "Togo", "address": "Bè Plage, Lomé",
        "latitude": Decimal("6.1375"), "longitude": Decimal("1.2254"),
        "listing_type": "short_stay", "price_per_night": Decimal("20000"),
        "bedrooms": 1, "bathrooms": 1, "beds_count": 1, "max_guests": 2,
        "cleaning_fee": Decimal("3000"), "security_deposit": Decimal("25000"),
        "cancellation_policy": "flexible", "instant_book": True,
        "check_in_time": time(14, 0), "check_out_time": time(11, 0),
    },
    {
        "host": hosts[0], "title": "Villa Assivito – 3 chambres avec jardin",
        "description": "Villa spacieuse dans le quartier Assivito. Jardin arboré, garage, cuisine américaine. Idéal pour séjour famille longue durée.",
        "city": "Lomé", "country": "Togo", "address": "Assivito, Lomé",
        "latitude": Decimal("6.1600"), "longitude": Decimal("1.2100"),
        "listing_type": "rent", "price_per_night": Decimal("30000"),
        "price_per_month": Decimal("600000"),
        "bedrooms": 3, "bathrooms": 2, "beds_count": 4, "max_guests": 6,
        "cleaning_fee": Decimal("10000"), "security_deposit": Decimal("100000"),
        "cancellation_policy": "moderate",
        "check_in_time": time(14, 0), "check_out_time": time(12, 0),
    },

    # ── Vente ──
    {
        "host": hosts[0], "title": "Terrain 500m² – Angré, Abidjan",
        "description": "Terrain viabilisé de 500m² à Angré, titre foncier disponible. Zone résidentielle calme, accès goudronné.",
        "city": "Abidjan", "country": "Côte d'Ivoire", "address": "Angré, Cocody, Abidjan",
        "latitude": Decimal("5.3700"), "longitude": Decimal("-3.9500"),
        "listing_type": "sale", "price_per_night": Decimal("25000000"),
        "bedrooms": 0, "bathrooms": 0, "beds_count": 0, "max_guests": 0,
        "cancellation_policy": "strict",
    },
    {
        "host": hosts[1], "title": "Maison 4 pièces à vendre – Calavi, Bénin",
        "description": "Maison neuve de 4 pièces à Abomey-Calavi. 3 chambres, salon, cuisine, garage. Quartier résidentiel sécurisé.",
        "city": "Abomey-Calavi", "country": "Bénin", "address": "Togba, Abomey-Calavi",
        "latitude": Decimal("6.4530"), "longitude": Decimal("2.3480"),
        "listing_type": "sale", "price_per_night": Decimal("35000000"),
        "bedrooms": 3, "bathrooms": 2, "beds_count": 0, "max_guests": 0,
        "cancellation_policy": "strict",
    },
]

listings = []
for data in listings_data:
    obj, created = Listing.objects.get_or_create(
        title=data["title"],
        defaults={**data, "is_published": True, "moderation_status": "approved"},
    )
    listings.append(obj)

print(f"  {len(listings)} annonces créées")

# ═══════════════════════════════════════════════════════════════
# 3. IMAGES (URLs from Unsplash — real estate photos)
# ═══════════════════════════════════════════════════════════════
print("Adding images...")

image_urls = [
    # Apartment interiors / exteriors — using picsum.photos for safe placeholder images
    ["https://picsum.photos/seed/apt1a/800/600", "https://picsum.photos/seed/apt1b/800/600", "https://picsum.photos/seed/apt1c/800/600"],
    ["https://picsum.photos/seed/studio2a/800/600", "https://picsum.photos/seed/studio2b/800/600"],
    ["https://picsum.photos/seed/villa3a/800/600", "https://picsum.photos/seed/villa3b/800/600", "https://picsum.photos/seed/villa3c/800/600", "https://picsum.photos/seed/villa3d/800/600"],
    ["https://picsum.photos/seed/loft4a/800/600", "https://picsum.photos/seed/loft4b/800/600", "https://picsum.photos/seed/loft4c/800/600"],
    ["https://picsum.photos/seed/family5a/800/600", "https://picsum.photos/seed/family5b/800/600", "https://picsum.photos/seed/family5c/800/600"],
    ["https://picsum.photos/seed/pent6a/800/600", "https://picsum.photos/seed/pent6b/800/600", "https://picsum.photos/seed/pent6c/800/600"],
    ["https://picsum.photos/seed/ngor7a/800/600", "https://picsum.photos/seed/ngor7b/800/600", "https://picsum.photos/seed/ngor7c/800/600"],
    ["https://picsum.photos/seed/alm8a/800/600", "https://picsum.photos/seed/alm8b/800/600"],
    ["https://picsum.photos/seed/lome9a/800/600", "https://picsum.photos/seed/lome9b/800/600"],
    ["https://picsum.photos/seed/villa10a/800/600", "https://picsum.photos/seed/villa10b/800/600", "https://picsum.photos/seed/villa10c/800/600"],
    ["https://picsum.photos/seed/terrain11a/800/600"],
    ["https://picsum.photos/seed/maison12a/800/600", "https://picsum.photos/seed/maison12b/800/600"],
]

for listing, urls in zip(listings, image_urls):
    for i, url in enumerate(urls):
        ListingImage.objects.get_or_create(
            listing=listing,
            image_url=url,
            defaults={"is_cover": i == 0},
        )

# ═══════════════════════════════════════════════════════════════
# 4. AMENITIES
# ═══════════════════════════════════════════════════════════════
print("Adding amenities...")

amenities_map = {
    0: [("WiFi haut débit", "indoor"), ("Climatisation", "indoor"), ("Cuisine équipée", "kitchen"), ("Machine à laver", "indoor"), ("TV écran plat", "entertainment")],
    1: [("WiFi", "indoor"), ("Climatisation", "indoor"), ("Parking gratuit", "outdoor"), ("Draps et serviettes", "bedroom")],
    2: [("Piscine privée", "outdoor"), ("WiFi", "indoor"), ("Climatisation", "indoor"), ("Jardin", "outdoor"), ("BBQ", "outdoor"), ("Parking", "outdoor"), ("Cuisine complète", "kitchen")],
    3: [("WiFi fibre", "indoor"), ("Smart TV", "entertainment"), ("Climatisation", "indoor"), ("Machine à café", "kitchen"), ("Espace de travail", "indoor")],
    4: [("WiFi", "indoor"), ("Climatisation", "indoor"), ("Balcon", "outdoor"), ("Gardien 24h", "outdoor"), ("Générateur", "indoor"), ("Cuisine équipée", "kitchen")],
    5: [("Jacuzzi", "indoor"), ("WiFi fibre", "indoor"), ("Climatisation", "indoor"), ("Terrasse panoramique", "outdoor"), ("Conciergerie", "indoor"), ("Parking sécurisé", "outdoor")],
    6: [("WiFi", "indoor"), ("Climatisation", "indoor"), ("Terrasse", "outdoor"), ("Vue mer", "outdoor"), ("Cuisine complète", "kitchen"), ("Jardin", "outdoor")],
    7: [("WiFi", "indoor"), ("Climatisation", "indoor"), ("Balcon vue mer", "outdoor"), ("Machine à laver", "indoor")],
    8: [("WiFi", "indoor"), ("Climatisation", "indoor"), ("Ménage quotidien", "indoor"), ("Petit-déjeuner", "kitchen")],
    9: [("WiFi", "indoor"), ("Climatisation", "indoor"), ("Jardin arboré", "outdoor"), ("Garage", "outdoor"), ("Cuisine américaine", "kitchen")],
}

for idx, amenities_list in amenities_map.items():
    if idx < len(listings):
        for name, cat in amenities_list:
            Amenity.objects.get_or_create(listing=listings[idx], name=name, defaults={"category": cat})

# ═══════════════════════════════════════════════════════════════
# 5. NEIGHBORHOOD PLACES
# ═══════════════════════════════════════════════════════════════
print("Adding neighborhood places...")

neighborhoods = {
    0: [
        ("health_center", "Centre de santé Haie Vive", 300),
        ("police_station", "Commissariat Central de Cotonou", 1000),
        ("shopping_center", "Erevan Supermarché", 800),
        ("pharmacy", "Pharmacie de la Haie Vive", 250),
        ("restaurant", "Chez Clarisse", 200),
        ("bank", "BOA Bénin (ATM)", 150),
        ("transport", "Gare routière Cotonou", 1500),
    ],
    2: [
        ("beach", "Plage de Fidjrossè", 500),
        ("restaurant", "Le Livingstone", 300),
        ("health_center", "Clinique Médicale Fidjrossè", 400),
        ("police_station", "Poste de Police Fidjrossè", 800),
        ("shopping_center", "Supermarché Erevan", 700),
        ("pharmacy", "Pharmacie Fidjrossè", 350),
    ],
    3: [
        ("health_center", "Polyclinique Sainte Anne", 600),
        ("police_station", "Commissariat du 8ème Arrondissement", 900),
        ("shopping_center", "Cap Sud Marcory", 1500),
        ("restaurant", "Ivoire Golf Club", 500),
        ("market", "Playce Marcory", 1200),
        ("pharmacy", "Pharmacie du Golf", 400),
        ("transport", "Gare de Bassam", 3000),
    ],
    5: [
        ("restaurant", "Le Plateau Lounge", 100),
        ("health_center", "CHU de Treichville", 1200),
        ("police_station", "Préfecture de Police d'Abidjan", 500),
        ("shopping_center", "Galerie Peyrissac", 300),
        ("pharmacy", "Pharmacie Centrale du Plateau", 200),
        ("transport", "Gare lagunaire SOTRA", 400),
        ("culture", "Musée des Civilisations", 600),
    ],
    6: [
        ("beach", "Plage de Ngor", 300),
        ("restaurant", "La Cabane du Surfeur", 150),
        ("health_center", "Centre de santé des Almadies", 500),
        ("police_station", "Commissariat des Almadies", 800),
        ("shopping_center", "Sea Plaza Dakar", 3500),
        ("pharmacy", "Pharmacie des Almadies", 300),
        ("transport", "Aéroport Blaise Diagne", 40000),
    ],
}

for idx, places in neighborhoods.items():
    if idx < len(listings):
        for cat, name, dist in places:
            NeighborhoodPlace.objects.get_or_create(
                listing=listings[idx], name=name,
                defaults={"category": cat, "distance_m": dist},
            )

# ═══════════════════════════════════════════════════════════════
# 6. BOOKINGS
# ═══════════════════════════════════════════════════════════════
from apps.bookings.models import Booking

print("Creating bookings...")

today = date.today()

bookings_data = [
    {"traveler": travelers[0], "listing": listings[0], "check_in": today + timedelta(days=5),  "check_out": today + timedelta(days=10), "guests": 2, "status": "confirmed"},
    {"traveler": travelers[1], "listing": listings[3], "check_in": today + timedelta(days=3),  "check_out": today + timedelta(days=7),  "guests": 1, "status": "confirmed"},
    {"traveler": travelers[2], "listing": listings[6], "check_in": today + timedelta(days=10), "check_out": today + timedelta(days=17), "guests": 4, "status": "pending"},
    {"traveler": travelers[0], "listing": listings[7], "check_in": today - timedelta(days=14), "check_out": today - timedelta(days=10), "guests": 2, "status": "completed"},
    {"traveler": travelers[1], "listing": listings[1], "check_in": today - timedelta(days=7),  "check_out": today - timedelta(days=3),  "guests": 1, "status": "completed"},
    {"traveler": travelers[2], "listing": listings[4], "check_in": today + timedelta(days=20), "check_out": today + timedelta(days=25), "guests": 3, "status": "pending_host"},
]

bookings = []
for data in bookings_data:
    listing = data["listing"]
    nights = (data["check_out"] - data["check_in"]).days
    subtotal = listing.price_per_night * nights
    commission = subtotal * Decimal("0.10")
    tax = subtotal * Decimal("0.05")
    total = subtotal + listing.cleaning_fee + commission + tax

    obj, created = Booking.objects.get_or_create(
        traveler=data["traveler"],
        listing=data["listing"],
        check_in=data["check_in"],
        defaults={
            "check_out": data["check_out"],
            "guests": data["guests"],
            "nightly_price": listing.price_per_night,
            "subtotal": subtotal,
            "cleaning_fee": listing.cleaning_fee,
            "commission": commission,
            "tax_amount": tax,
            "total_amount": total,
            "status": data["status"],
        },
    )
    bookings.append(obj)

print(f"  {len(bookings)} réservations")

# ═══════════════════════════════════════════════════════════════
# 7. REVIEWS (only for completed bookings)
# ═══════════════════════════════════════════════════════════════
from apps.reviews.models import Review

print("Creating reviews...")

reviews_data = [
    {
        "listing": listings[7], "author": travelers[0], "booking": bookings[3],
        "rating": 5, "rating_cleanliness": 5, "rating_communication": 5,
        "rating_location": 4, "rating_value": 5, "rating_accuracy": 5,
        "comment": "Studio parfait aux Almadies ! Vue mer magnifique, très propre. Fatou est une hôte exceptionnelle.",
        "visibility": "published",
    },
    {
        "listing": listings[1], "author": travelers[1], "booking": bookings[4],
        "rating": 4, "rating_cleanliness": 4, "rating_communication": 5,
        "rating_location": 5, "rating_value": 4, "rating_accuracy": 4,
        "comment": "Très bon studio à Fidjrossè, proche de la plage. Le WiFi pourrait être plus rapide mais sinon rien à redire.",
        "visibility": "published",
    },
]

for data in reviews_data:
    Review.objects.get_or_create(
        listing=data["listing"],
        author=data["author"],
        defaults=data,
    )

# ═══════════════════════════════════════════════════════════════
# 8. WALLETS
# ═══════════════════════════════════════════════════════════════
from apps.payments.models import Wallet

print("Creating wallets...")

for host in hosts:
    Wallet.objects.get_or_create(user=host, defaults={"balance": Decimal("0"), "currency": "XOF"})

for traveler in travelers:
    Wallet.objects.get_or_create(user=traveler, defaults={"balance": Decimal("100000"), "currency": "XOF"})

# ═══════════════════════════════════════════════════════════════
# 9. CONVERSATIONS & MESSAGES
# ═══════════════════════════════════════════════════════════════
from apps.messaging.models import Conversation, Message

print("Creating conversations...")

# Conversation between Jean and Koffi about listing 0
conv1, _ = Conversation.objects.get_or_create(booking=bookings[0])
conv1.participants.add(travelers[0], hosts[1])
Message.objects.get_or_create(conversation=conv1, sender=travelers[0], defaults={"content": "Bonjour ! L'appartement est-il disponible pour 5 nuits ?"})
Message.objects.get_or_create(conversation=conv1, sender=hosts[1], defaults={"content": "Bonjour Jean ! Oui, l'appartement est disponible. Je vous confirme la réservation."})

# Conversation between Marie and Aminata about listing 3
conv2, _ = Conversation.objects.get_or_create(booking=bookings[1])
conv2.participants.add(travelers[1], hosts[0])
Message.objects.get_or_create(conversation=conv2, sender=travelers[1], defaults={"content": "Bonjour, est-ce que le parking est sécurisé ?"})
Message.objects.get_or_create(conversation=conv2, sender=hosts[0], defaults={"content": "Oui, le parking est surveillé 24h/24 avec un gardien. Vous pouvez garer votre véhicule en toute sécurité."})

print("\n✅ Base de données peuplée avec succès !")
print(f"   • {User.objects.count()} utilisateurs")
print(f"   • {Listing.objects.count()} annonces")
print(f"   • {ListingImage.objects.count()} photos")
print(f"   • {Amenity.objects.count()} équipements")
print(f"   • {Booking.objects.count()} réservations")
print(f"   • {Review.objects.count()} avis")
print(f"   • {Conversation.objects.count()} conversations")
