from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models

from .faculty import Faculty
from .course import Course
from .semester import Semester


class Section(models.Model):
    """A class that inherits from the model class which 
    create a Section model.This Section model defines a 
    datastore entity.
    This class is ordering by reference number and has a
    unique together field of semester and reference.

    Args:
        models (_type_): model class

    Returns:
        _type_: string object (Section.reference, Section.course, and Section.name)
    """
    reference = models.IntegerField(
        validators=[MaxValueValidator(100000), MinValueValidator(0)])
    name = models.CharField(max_length=10)
    course = models.ForeignKey(Course, on_delete=models.CASCADE)
    instructor = models.ForeignKey(Faculty, on_delete=models.CASCADE)
    semester = models.ForeignKey(Semester, on_delete=models.CASCADE)

    def __str__(self) -> str:
        return f'{self.reference} {self.course} {self.name}'

    class Meta:
        ordering = ['reference']
        unique_together = (('semester', 'reference'),)
