from django.core.management.base import BaseCommand
from apparel.models import TShirtSize

class Command(BaseCommand):
    help = 'Updates the order of T-shirt sizes from smallest to largest'

    def handle(self, *args, **options):
        # Define the order of sizes from smallest to largest
        size_order = {
            'S': 1,     # Small
            'M': 2,     # Medium
            'L': 3,     # Large
            'XL': 4,    # Extra Large
            'XXL': 5,   # Double Extra Large
            'XXXL': 6,  # Triple Extra Large
        }

        # Update each size with its order value
        for code, order in size_order.items():
            try:
                size = TShirtSize.objects.get(code=code)
                size.order = order
                size.save()
                self.stdout.write(self.style.SUCCESS(f"Updated order for {size.name} ({size.code}) to {order}"))
            except TShirtSize.DoesNotExist:
                self.stdout.write(self.style.WARNING(f"Size with code {code} not found"))

        self.stdout.write(self.style.SUCCESS('Successfully updated T-shirt size order'))
