from django.core.management.base import BaseCommand
from batch_year.models import BatchYear
from django.utils.text import slugify

class Command(BaseCommand):
    help = 'Populates initial BatchYear data'

    def handle(self, *args, **options):
        batch_years_data = [
            {'title': 'First Year', 'code': '1st'},
            {'title': 'Second Year', 'code': '2nd'},
            {'title': 'Third Year', 'code': '3rd'},
            {'title': 'Fourth Year', 'code': '4th'},
        ]

        for data in batch_years_data:
            title = data['title']
            code = data['code']
            slug = slugify(title)

            BatchYear.objects.get_or_create(
                title=title,
                defaults={'slug': slug, 'code': code}
            )
            self.stdout.write(self.style.SUCCESS(f'Successfully added/updated BatchYear: {title}'))

        self.stdout.write(self.style.SUCCESS('BatchYear data population complete.'))
