from django.db import models
from django.conf import settings
from django.utils.translation import gettext_lazy as _

# ---------------------------------------------------------------------------
# Incident
# ---------------------------------------------------------------------------
class Incident(models.Model):
    """Incidents and related risks."""

    class Meta:
        verbose_name = _("Incident")
        verbose_name_plural = _("Incidents")

    STATUS_CHOICES = [
        ("open", _("Opened")),
        ("in_progress", _("In Progress")),
        ("closed", _("Closed")),
    ]

    title = models.CharField(_("Title"), max_length=255)
    description = models.TextField(_("Description"), blank=True, null=True)
    date_reported = models.DateField(_("Date reported"), blank=True, null=True)
    reported_by = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        verbose_name=_("Reported by"),
        null=True, blank=True,
        on_delete=models.SET_NULL,
        related_name="incidents"
    )
    status = models.CharField(max_length=12, choices=STATUS_CHOICES)
    related_risks = models.ManyToManyField("Risk", blank=True, related_name="incidents")
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

