from django.db import models
from django.contrib.postgres.fields import ArrayField
from django.core.validators import MaxValueValidator, MinValueValidator
from .major import Major


from .section import Section


class Responses(models.Model):
    """A class that inherits from the model class which 
    create a Responses model.This Responses model defines a 
    datastore entity.
    This class is ordering by Responses.section.

    Args:
        models (_type_): model class

    Returns:
        _type_: string object (Responses.section and Responses.major)
    """
    section = models.ForeignKey(Section, on_delete=models.DO_NOTHING)
    major = models.ForeignKey(Major, on_delete=models.DO_NOTHING)

    gen_answers = ArrayField(models.IntegerField(
        validators=[MinValueValidator(1), MaxValueValidator(5)]))
    cs_answers = ArrayField(models.IntegerField(
        validators=[MinValueValidator(1), MaxValueValidator(5)]))
    major_answers = ArrayField(models.IntegerField(
        validators=[MinValueValidator(1), MaxValueValidator(5)]))

    comments = models.TextField(blank=True, null=True)

    def __str__(self) -> str:
        return f'{self.section} {self.major}'

    class Meta:
        ordering = ['section']
