from django.db import models
from django.utils.translation import gettext_lazy
from django_celery_beat.models import PeriodicTask
from solo.models import SingletonModel

from core.fields import IntegerField
from rotation.constants import DEFAULT_ROTATION_SIZE
from rotation.enums import RotationType


class RotationSettings(SingletonModel):
    """ Base model for Object rotation settings """

    rotation_type = IntegerField(choices=RotationType.choices,
                                 verbose_name=gettext_lazy('Rotation type'),
                                 default=RotationType.DISABLED)
    size_rotation = IntegerField(default=DEFAULT_ROTATION_SIZE,
                                 min_value=1,
                                 verbose_name=gettext_lazy('Size of table when rotation occurs'),
                                 help_text=gettext_lazy('Size of table'),
                                 null=True,
                                 blank=True)
    task = models.ForeignKey(PeriodicTask,
                             null=True,
                             blank=True,
                             verbose_name=gettext_lazy('Task'),
                             help_text=gettext_lazy('Periodic task'),
                             on_delete=models.SET_NULL)

    class Meta:
        abstract = True


class IncidentRotationSettings(RotationSettings):
    singleton_instance_id = 5


class EventRotationSettings(RotationSettings):
    singleton_instance_id = 1
