from django.core.management.base import BaseCommand
from community.models import Room

DEFAULT_ROOMS = [
    # Neighborhoods
    {"name": "Makongeni", "slug": "makongeni", "room_type": "neighborhood", "icon": "🏘️", "description": "Chat for Makongeni estate residents"},
    {"name": "Township", "slug": "township", "room_type": "neighborhood", "icon": "🏙️", "description": "Thika Township residents"},
    {"name": "Landless", "slug": "landless", "room_type": "neighborhood", "icon": "🌳", "description": "Landless estate chat"},
    {"name": "Section 9", "slug": "section-9", "room_type": "neighborhood", "icon": "🏠", "description": "Section 9 residents"},
    {"name": "Ngoigwa", "slug": "ngoigwa", "room_type": "neighborhood", "icon": "🏡", "description": "Ngoigwa estate chat"},
    {"name": "Gatuanyaga", "slug": "gatuanyaga", "room_type": "neighborhood", "icon": "🌿", "description": "Gatuanyaga community"},

    # Topics
    {"name": "Jobs & Kazi", "slug": "jobs", "room_type": "topic", "icon": "💼", "description": "Job openings and opportunities in Thika"},
    {"name": "Biashara", "slug": "biashara", "room_type": "business", "icon": "🛒", "description": "Business promotions, buy and sell"},
    {"name": "Matatu & Transport", "slug": "transport", "room_type": "topic", "icon": "🚌", "description": "Route updates, fare changes"},
    {"name": "Lost & Found", "slug": "lost-found", "room_type": "topic", "icon": "🔍", "description": "Lost or found items in Thika"},
    {"name": "News & Habari", "slug": "news", "room_type": "topic", "icon": "📰", "description": "Local Thika news"},
    {"name": "Events", "slug": "events", "room_type": "topic", "icon": "🎉", "description": "Events happening in Thika"},
    {"name": "Water & Power", "slug": "utilities", "room_type": "topic", "icon": "💧", "description": "KPLC outages, water alerts"},

    # Universities
    {"name": "MKU Students", "slug": "mku", "room_type": "university", "icon": "🎓", "description": "Mount Kenya University students"},
    {"name": "Dedan Kimathi", "slug": "dkut", "room_type": "university", "icon": "🎓", "description": "DeKUT students"},

    # Elections
    {"name": "Thika East Ward", "slug": "thika-east", "room_type": "election", "icon": "🗳️", "description": "Thika East ward issues"},
    {"name": "Thika West Ward", "slug": "thika-west", "room_type": "election", "icon": "🗳️", "description": "Thika West ward issues"},
    {"name": "Candidate Corner", "slug": "candidates", "room_type": "election", "icon": "📢", "description": "Discuss 2027 candidates"},
]


class Command(BaseCommand):
    help = "Seed default ThikaConnect chat rooms"

    def handle(self, *args, **kwargs):
        created = 0
        for room_data in DEFAULT_ROOMS:
            room, was_created = Room.objects.get_or_create(
                slug=room_data["slug"],
                defaults=room_data,
            )
            if was_created:
                created += 1
                self.stdout.write(self.style.SUCCESS(f"  Created: {room}"))
            else:
                self.stdout.write(f"  Exists:  {room}")

        self.stdout.write(self.style.SUCCESS(f"\n✅ Done. {created} new rooms created."))