# Path: statusboard/models.py
# class Service(TimeStampedModel):
#     name = models.CharField(
#         max_length=255, unique=True, verbose_name=_("name")
#     )
#     description = models.TextField(blank=True, verbose_name=_("description"))
#     href = models.URLField(blank=True)
#     status = models.IntegerField(
#         choices=SERVICE_STATUSES, verbose_name=_("status")
#     )
#     priority = models.PositiveIntegerField(
#         default=0, verbose_name=_("priority")
#     )
#     groups = models.ManyToManyField(
#         "ServiceGroup",
#         blank=True,
#         related_name="services",
#         related_query_name="service",
#         verbose_name=_("groups"),
#     )
#     objects = ServiceManager()
# 
#     def __str__(self):
#         return self.name
# 
#     def __init__(self, *args, **kwargs):
#         super(Service, self).__init__(*args, **kwargs)
#         self._status = self.status
# 
#     def save(self, *args, **kwargs):
#         # When the instance is saved, the original status is updated
#         super(Service, self).save(*args, **kwargs)
#         self._status = self.status
# 
#     class Meta:
#         verbose_name = _("service")
#         verbose_name_plural = _("services")
# 
# class ServiceGroup(TimeStampedModel):
#     name = models.CharField(
#         max_length=255, unique=True, verbose_name=_("name")
#     )
#     priority = models.PositiveIntegerField(
#         default=0, verbose_name=_("priority")
#     )
#     collapse = models.IntegerField(
#         choices=SERVICEGROUP_COLLAPSE_OPTIONS, default=0
#     )
#     objects = ServiceGroupManager()
# 
#     def worst_service(self):
#         return self.services.all().latest("status")
# 
#     def collapsed(self):
#         """Check if the service group should collapse or not.
# 
#         Return true if a group doesn't have any service."""
#         if self.collapse == 0:
#             return False
#         elif self.collapse == 1:
#             return True
#         else:
#             return not self.services.exclude(status=0).exists()
# 
#     def is_empty_group(self):
#         return not self.services.all().exists()
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name = _("service group")
#         verbose_name_plural = _("service groups")
# 
# class Incident(TimeStampedModel):
#     name = models.CharField(max_length=255, verbose_name=_("name"))
#     services = models.ManyToManyField(
#         "Service",
#         blank=True,
#         related_name="incidents",
#         related_query_name="incident",
#         verbose_name=_("services"),
#     )
#     occurred = models.DateTimeField(
#         default=timezone.now, verbose_name=_("occurred")
#     )
#     closed = models.BooleanField(default=False)
#     objects = IncidentManager()
# 
#     def updates_by_ctime(self):
#         return self.updates.order_by("-created")
# 
#     def should_be_closed(self):
#         try:
#             return self.updates.latest("created").status == 3
#         except IncidentUpdate.DoesNotExist:
#             return False
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name = _("incident")
#         verbose_name_plural = _("incidents")
# 
# class IncidentUpdate(TimeStampedModel):
#     incident = models.ForeignKey(
#         Incident,
#         related_name="updates",
#         on_delete=models.deletion.CASCADE,
#         related_query_name="update",
#         verbose_name=_("incident"),
#     )
#     status = models.IntegerField(
#         choices=INCIDENT_STATUSES, verbose_name=_("status")
#     )
#     description = models.TextField(verbose_name=_("description"))
# 
#     def __str__(self):
#         return "Update {} {}".format(self.incident.name, self.modified)
# 
#     class Meta:
#         verbose_name = _("incident update")
#         verbose_name_plural = _("incident updates")
# 
# class Maintenance(TimeStampedModel):
#     scheduled = models.DateTimeField(verbose_name=_("scheduled start"))
#     name = models.CharField(max_length=255, verbose_name=_("name"))
#     description = models.TextField(verbose_name=_("description"))
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name = _("maintenance")
#         verbose_name_plural = _("maintenances")


from rest_framework import serializers
from .models import (
    Service,
    ServiceGroup,
    Incident,
    IncidentUpdate,
    Maintenance,
)
class ServiceGroupSerializer(serializers.ModelSerializer):
    class Meta:
        model = ServiceGroup
        fields = (
            "id",
            "name",
            "collapse",
            "priority",
            "services",
            "created",
            "modified",
        )


class IncidentSerializer(serializers.ModelSerializer):
    class Meta:
        model = Incident
        fields = (
            "id",
            "name",
            "services",
            "occurred",
            "created",
            "modified",
            "updates",
            "closed",
        )
        read_only_fields = ("closed",)



# Path: statusboard/models.py
# class Service(TimeStampedModel):
#     name = models.CharField(
#         max_length=255, unique=True, verbose_name=_("name")
#     )
#     description = models.TextField(blank=True, verbose_name=_("description"))
#     href = models.URLField(blank=True)
#     status = models.IntegerField(
#         choices=SERVICE_STATUSES, verbose_name=_("status")
#     )
#     priority = models.PositiveIntegerField(
#         default=0, verbose_name=_("priority")
#     )
#     groups = models.ManyToManyField(
#         "ServiceGroup",
#         blank=True,
#         related_name="services",
#         related_query_name="service",
#         verbose_name=_("groups"),
#     )
#     objects = ServiceManager()
# 
#     def __str__(self):
#         return self.name
# 
#     def __init__(self, *args, **kwargs):
#         super(Service, self).__init__(*args, **kwargs)
#         self._status = self.status
# 
#     def save(self, *args, **kwargs):
#         # When the instance is saved, the original status is updated
#         super(Service, self).save(*args, **kwargs)
#         self._status = self.status
# 
#     class Meta:
#         verbose_name = _("service")
#         verbose_name_plural = _("services")
# 
# class ServiceGroup(TimeStampedModel):
#     name = models.CharField(
#         max_length=255, unique=True, verbose_name=_("name")
#     )
#     priority = models.PositiveIntegerField(
#         default=0, verbose_name=_("priority")
#     )
#     collapse = models.IntegerField(
#         choices=SERVICEGROUP_COLLAPSE_OPTIONS, default=0
#     )
#     objects = ServiceGroupManager()
# 
#     def worst_service(self):
#         return self.services.all().latest("status")
# 
#     def collapsed(self):
#         """Check if the service group should collapse or not.
# 
#         Return true if a group doesn't have any service."""
#         if self.collapse == 0:
#             return False
#         elif self.collapse == 1:
#             return True
#         else:
#             return not self.services.exclude(status=0).exists()
# 
#     def is_empty_group(self):
#         return not self.services.all().exists()
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name = _("service group")
#         verbose_name_plural = _("service groups")
# 
# class Incident(TimeStampedModel):
#     name = models.CharField(max_length=255, verbose_name=_("name"))
#     services = models.ManyToManyField(
#         "Service",
#         blank=True,
#         related_name="incidents",
#         related_query_name="incident",
#         verbose_name=_("services"),
#     )
#     occurred = models.DateTimeField(
#         default=timezone.now, verbose_name=_("occurred")
#     )
#     closed = models.BooleanField(default=False)
#     objects = IncidentManager()
# 
#     def updates_by_ctime(self):
#         return self.updates.order_by("-created")
# 
#     def should_be_closed(self):
#         try:
#             return self.updates.latest("created").status == 3
#         except IncidentUpdate.DoesNotExist:
#             return False
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name = _("incident")
#         verbose_name_plural = _("incidents")
# 
# class IncidentUpdate(TimeStampedModel):
#     incident = models.ForeignKey(
#         Incident,
#         related_name="updates",
#         on_delete=models.deletion.CASCADE,
#         related_query_name="update",
#         verbose_name=_("incident"),
#     )
#     status = models.IntegerField(
#         choices=INCIDENT_STATUSES, verbose_name=_("status")
#     )
#     description = models.TextField(verbose_name=_("description"))
# 
#     def __str__(self):
#         return "Update {} {}".format(self.incident.name, self.modified)
# 
#     class Meta:
#         verbose_name = _("incident update")
#         verbose_name_plural = _("incident updates")
# 
# class Maintenance(TimeStampedModel):
#     scheduled = models.DateTimeField(verbose_name=_("scheduled start"))
#     name = models.CharField(max_length=255, verbose_name=_("name"))
#     description = models.TextField(verbose_name=_("description"))
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name = _("maintenance")
#         verbose_name_plural = _("maintenances")


# Path: statusboard/serializers.py
from rest_framework import serializers
from .models import (
    Service,
    ServiceGroup,
    Incident,
    IncidentUpdate,
    Maintenance,
)

class ServiceGroupSerializer(serializers.ModelSerializer):
    class Meta:
        model = ServiceGroup
        fields = (
            "id",
            "name",
            "collapse",
            "priority",
            "services",
            "created",
            "modified",
        )


class IncidentSerializer(serializers.ModelSerializer):
    class Meta:
        model = Incident
        fields = (
            "id",
            "name",
            "services",
            "occurred",
            "created",
            "modified",
            "updates",
            "closed",
        )
        read_only_fields = ("closed",)



class IncidentUpdateSerializer(serializers.ModelSerializer):