"""
Serializers for Notification Log API.
"""

from rest_framework import serializers

from apps.core.choices.serializers import RichChoiceSerializerField
from apps.notifications.models import NotificationLog


class NotificationLogSerializer(serializers.ModelSerializer):
    """Serializer for notification logs."""

    status = RichChoiceSerializerField(
        choice_group="notification_log_statuses",
        domain="notifications",
    )
    user_username = serializers.CharField(
        source="user.username",
        read_only=True,
        allow_null=True,
    )
    user_email = serializers.EmailField(
        source="user.email",
        read_only=True,
        allow_null=True,
    )

    class Meta:
        model = NotificationLog
        fields = [
            "id",
            "user",
            "user_username",
            "user_email",
            "workflow_id",
            "notification_type",
            "channel",
            "status",
            "payload",
            "error_message",
            "novu_transaction_id",
            "created_at",
            "updated_at",
        ]
        read_only_fields = ["id", "created_at", "updated_at", "user_username", "user_email"]
