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


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

    Args:
        models (_type_): model class

    Returns:
        _type_: string object (Semester.year, Semester.semester_name)
    """
    month = models.IntegerField(default=1, verbose_name='Number of month (1-12)',
                                validators=[MinValueValidator(1), MaxValueValidator(12)])
    year = models.IntegerField(default=2000, verbose_name='Year (4 digits)', validators=[
                               MinValueValidator(2000), MaxValueValidator(3000)])

    def semester_name(self):
        if self.month > 1 and self.month <= 5:
            return 'Spring'
        elif self.month > 5 and self.month <= 8:
            return 'Summer'
        else:
            return 'Fall'

    def __str__(self) -> str:
        return f'{self.year} {self.semester_name()}'

    class Meta:
        ordering = ['year']
        unique_together = (('month', 'year'),)
