from django.core.management.base import BaseCommand
from core.models import Category

class Command(BaseCommand):
    help = 'Prepopulate hierarchical categories'

    def handle(self, *args, **options):
        # Full Reset
        Category.objects.all().delete()

        hierarchy = {
            'wardrobe': {
                'Jackets': ['Jackets', 'Coats', 'Zip-Ups'],
                'Shirts': ['Hoodies', 'Pullover', 'Sweater', 'Turtlenecks', 'Shirts'],
                'T-Shirts': ['T-Shirts', 'Armless Shirts', 'Tanktops'],
                'Pants': ['Jeans', 'Pants', 'Cargo Pants', 'Linen'],
                'Shorts': ['Shorts', 'Jorts'],
                'Suit': ['Suits', 'Suit Jackets', 'Shirts', 'Suit Pants', 'Suit Shoes'],
                'Shoes': ['Shoes', 'Sneakers', 'Boots', 'Suit Shoes'],
            },
            'accessory': {
                'Jewelry': ['Rings', 'Pant Chains'],
                'Headwear': ['Headwear'],
            }
        }

        for item_type, parents in hierarchy.items():
            for parent_name, children in parents.items():
                parent_cat = Category.objects.create(
                    name=parent_name, 
                    item_type=item_type,
                    parent=None,
                    is_preset=True
                )

                for child_name in children:
                    Category.objects.create(
                        name=child_name,
                        item_type=item_type,
                        parent=parent_cat,
                        is_preset=True
                    )

        self.stdout.write(self.style.SUCCESS('Successfully reset and prepopulated hierarchical categories'))
