from django.core.management.base import BaseCommand
from apps.institutions.import_requirements import import_programmes_with_requirements


class Command(BaseCommand):
    help = 'Import programmes with requirements from CSV'
    
    def add_arguments(self, parser):
        parser.add_argument('--file', type=str, required=True, help='CSV file path')
    
    def handle(self, *args, **options):
        created, updated, errors = import_programmes_with_requirements(options['file'])
        
        self.stdout.write(self.style.SUCCESS(f'Created: {created}'))
        self.stdout.write(self.style.SUCCESS(f'Updated: {updated}'))
        if errors:
            self.stdout.write(self.style.ERROR(f'Errors: {len(errors)}'))
            for error in errors[:5]:
                self.stdout.write(self.style.ERROR(f'  - {error}'))