from django.core.management.base import BaseCommand
from exams.models import Student, StudentAbility, DailyQuestionCount

class Command(BaseCommand):
    help = 'Assigns daily academic questions based on student ability.'

    def handle(self, *args, **options):
        students = Student.objects.filter(is_active=True)
        for s in students:
            ability, _ = StudentAbility.objects.get_or_create(student=s)
            daily_count, _ = DailyQuestionCount.objects.get_or_create(student=s)
            
            # Simple adaptive logic: Tier 1-2 get 5 questions, Tier 3-4 get 3, Tier 5 gets 2.
            if s.tier in [1, 2]:
                target = 5
            elif s.tier in [3, 4]:
                target = 3
            else:
                target = 2
                
            self.stdout.write(f"Student {s.code} ({s.name}): Assigned {target} questions.")
