from django.forms import (
    Form,
    ModelForm,
    ModelMultipleChoiceField,
    ModelChoiceField,
    ChoiceField,
    CharField,
)
from django.forms import inlineformset_factory

from generic.forms import ExamAuthorFormMixin, ExamFormMixin, ExamGroupsFormMixin, ExamMarkerFormMixin

from .models import (
    Question,
    UserAnswer,
    Exam,
)

from django.contrib.admin.widgets import FilteredSelectMultiple
from django.forms.widgets import RadioSelect, TextInput, Textarea


class UserAnswerForm(ModelForm):
    class Meta:
        model = UserAnswer
        fields = ["a", "b", "c", "d", "e"]

    def __init__(self, *args, **kwargs):
        super(UserAnswerForm, self).__init__(*args, **kwargs)
        #self.fields['answer'].required = False



# This should be made generic?
class ExamForm(ExamFormMixin, ModelForm):
    class Meta(ExamFormMixin.Meta):
        model = Exam

class ExamAuthorForm(ExamAuthorFormMixin):
    class Meta(ExamAuthorFormMixin.Meta):
        model = Exam

class ExamMarkerForm(ExamMarkerFormMixin):
    class Meta(ExamMarkerFormMixin.Meta):
        model = Exam


class ExamGroupsForm(ExamGroupsFormMixin):
    class Meta(ExamGroupsFormMixin.Meta):
        model = Exam


class QuestionForm(ModelForm):
    class Meta:
        model = Question
        fields = [
            "stem",
            "a",
            "a_answer",
            "a_feedback",
            "b",
            "b_answer",
            "b_feedback",
            "c",
            "c_answer",
            "c_feedback",
            "d",
            "d_answer",
            "d_feedback",
            "e",
            "e_answer",
            "e_feedback",
            "category",
        ]

    def __init__(self, *args, **kwargs):
        # accept an optional user kwarg for parity with other apps
        self.user = kwargs.pop("user", None)
        super().__init__(*args, **kwargs)