from django.db import models
from django.utils.translation import gettext_lazy as _
from notifications.base.models import AbstractNotification

from vbv_lernwelt.course.models import CourseSession


class NotificationCategory(models.TextChoices):
    USER_INTERACTION = "USER_INTERACTION", _("User Interaction")
    PROGRESS = "PROGRESS", _("Progress")
    INFORMATION = "INFORMATION", _("Information")


class NotificationTrigger(models.TextChoices):
    ATTENDANCE_COURSE_REMINDER = "ATTENDANCE_COURSE_REMINDER", _(
        "Attendance Course Reminder"
    )
    ASSIGNMENT_REMINDER = "ASSIGNMENT_REMINDER", _("Assignment Reminder")
    CASEWORK_EXPERT_EVALUATION_REMINDER = (
        "CASEWORK_EXPERT_EVALUATION_REMINDER",
        _("Casework Expert Evaluation Reminder"),
    )
    CASEWORK_SUBMITTED = "CASEWORK_SUBMITTED", _("Casework Submitted")
    CASEWORK_EVALUATED = "CASEWORK_EVALUATED", _("Casework Evaluated")
    NEW_FEEDBACK = "NEW_FEEDBACK", _("New Feedback")


class Notification(AbstractNotification):
    # UUIDs are not supported by the notifications app...
    # id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

    notification_category = models.CharField(
        max_length=255,
        choices=NotificationCategory.choices,
        default=NotificationCategory.INFORMATION,
    )
    notification_trigger = models.CharField(
        max_length=255,
        choices=NotificationTrigger.choices,
        default="",
    )
    target_url = models.CharField(max_length=2048, default="", blank=True)
    actor_avatar_url = models.CharField(max_length=2048, default="", blank=True)
    course_session = models.ForeignKey(
        CourseSession, blank=True, null=True, on_delete=models.SET_NULL
    )

    class Meta(AbstractNotification.Meta):
        abstract = False
        ordering = ["-timestamp"]
