from django.core.management.base import BaseCommand
from exams.models import Student
from exams.services.whatsapp import send_whatsapp_message

class Command(BaseCommand):
    help = 'Sends a WhatsApp alert to a parent (Placeholder Safe)'

    def add_arguments(self, parser):
        parser.add_argument('student_code', type=str)
        parser.add_argument('message', type=str)

    def handle(self, *args, **options):
        code = options['student_code']
        msg = options['message']
        student = Student.objects.filter(code=code).first()
        if student and student.whatsapp_consent and student.whatsapp_parent:
            success = send_whatsapp_message(student.whatsapp_parent, msg)
            if success: self.stdout.write(self.style.SUCCESS("Alert processed."))
        else:
            self.stdout.write(self.style.ERROR("Consent or phone number missing."))
