from django import forms
from django.db import models
from django.forms import ModelForm

from users.models import User
# Create your models here.

class Classroom(models.Model):
    name = models.CharField(max_length=30)
    grade = models.CharField(max_length=4)
    teacher = models.ForeignKey(User, on_delete=models.CASCADE)
    average_at_risk = models.IntegerField(null=False, blank=True, default=0)

    def __str__(self):
        return self.name


class ClassroomForm(ModelForm):
    class Meta:
        model = Classroom
        fields = ['name', 'grade']


class Student(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    date_of_birth = models.DateField()
    grade = models.CharField(max_length=4)
    teacher = models.ForeignKey(User, on_delete=models.CASCADE)
    classroom = models.ForeignKey(Classroom, on_delete=models.CASCADE)
    GENDER_CHOICES = (
        ('M', 'Male'),
        ('F', 'Female')
    )
    gender = models.CharField(max_length=1, choices=GENDER_CHOICES)

    # Test Related
    QUESTION_CHOICES = (
        ('Y', 'Correct Answer'),
        ('N', 'Incorrect Answer'),
        ('D', 'No Answer')
    )

    EXAM_BOOLEAN = (
        ('Y', 'Student has taken the exam'),
        ('N', 'Student has not taken the exam')
    )

    exam_taken = models.CharField(max_length=1, choices=EXAM_BOOLEAN, default='N')
    
    RISK_LEVEL = (
        ('GREAT', 'Student is not at risk'),
        ('AT_RISK', 'Student is at risk.'),
        ('UNKNOWN', 'Student risk level is unknown')
    )
    risk = models.CharField(max_length=7, choices=RISK_LEVEL, default='UNKNOWN')

    question_1 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_2 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_3 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_4 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_5 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_6 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_7 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_8 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_9 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_10 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_11 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_12 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_13 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_14 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_15 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_16 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_17 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_18 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_19 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_20 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_21 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_22 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_23 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_24 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_25 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    question_26 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_1 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_2 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_3 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_4 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_5 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_6 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_7 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_8 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_9 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_10 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_11 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_12 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_13 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_14 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_15 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_16 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_17 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_18 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_19 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_20 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_21 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_22 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_23 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_24 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_25 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_26 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_27 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_28 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_29 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_30 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p2question_31 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p3question_1 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p3question_2 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p3question_3 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p3question_4 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p3question_5 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p3question_6 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p3question_7 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p3question_8 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p4question_1 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p4question_2 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p4question_3 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p4question_4 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p4question_5 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p4question_6 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p5question_1 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p5question_2 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p5question_3 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p5question_4 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')
    p5question_5 = models.CharField(max_length=1, choices=QUESTION_CHOICES, default='D')

    timespent = models.IntegerField(default=0)

    max_questions_wrong = models.IntegerField(default=0)


class StudentForm(ModelForm):
    class Meta:
        model = Student
        fields = ['first_name', 'last_name', 'date_of_birth', 'classroom', 'gender']




