# Generated by Django 4.2.24 on 2025-11-02 04:28

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import opencontractserver.shared.defaults
import opencontractserver.shared.fields


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("conversations", "0007_corpusmoderator_conversation_is_locked_and_more"),
    ]

    operations = [
        migrations.CreateModel(
            name="Notification",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "notification_type",
                    models.CharField(
                        choices=[
                            ("REPLY", "Reply to Message"),
                            ("VOTE", "Vote on Message"),
                            ("BADGE", "Badge Awarded"),
                            ("MENTION", "Mentioned in Message"),
                            ("ACCEPTED", "Answer Accepted"),
                            ("THREAD_LOCKED", "Thread Locked"),
                            ("THREAD_UNLOCKED", "Thread Unlocked"),
                            ("THREAD_PINNED", "Thread Pinned"),
                            ("THREAD_UNPINNED", "Thread Unpinned"),
                            ("MESSAGE_DELETED", "Message Deleted"),
                            ("THREAD_DELETED", "Thread Deleted"),
                            ("MESSAGE_RESTORED", "Message Restored"),
                            ("THREAD_RESTORED", "Thread Restored"),
                            ("THREAD_REPLY", "Reply in Thread You're Participating In"),
                        ],
                        help_text="Type of notification",
                        max_length=20,
                    ),
                ),
                (
                    "is_read",
                    models.BooleanField(
                        db_index=True,
                        default=False,
                        help_text="Whether the notification has been read",
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        db_index=True,
                        help_text="When the notification was created",
                    ),
                ),
                (
                    "modified",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="When the notification was last modified",
                    ),
                ),
                (
                    "data",
                    opencontractserver.shared.fields.NullableJSONField(
                        blank=True,
                        default=opencontractserver.shared.defaults.jsonfield_default_value,
                        help_text="Additional context data for the notification (e.g., vote type, badge info)",
                        null=True,
                    ),
                ),
                (
                    "actor",
                    models.ForeignKey(
                        blank=True,
                        help_text="User who triggered this notification (if applicable)",
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="notifications_triggered",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "conversation",
                    models.ForeignKey(
                        blank=True,
                        help_text="Related conversation/thread if applicable",
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="notifications",
                        to="conversations.conversation",
                    ),
                ),
                (
                    "message",
                    models.ForeignKey(
                        blank=True,
                        help_text="Related message if applicable",
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="notifications",
                        to="conversations.chatmessage",
                    ),
                ),
                (
                    "recipient",
                    models.ForeignKey(
                        help_text="User receiving this notification",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="notifications",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "ordering": ["-created_at"],
                "indexes": [
                    models.Index(
                        fields=["recipient", "-created_at"],
                        name="notificatio_recipie_a972ce_idx",
                    ),
                    models.Index(
                        fields=["recipient", "is_read"],
                        name="notificatio_recipie_4e3567_idx",
                    ),
                    models.Index(
                        fields=["notification_type"],
                        name="notificatio_notific_f2898f_idx",
                    ),
                    models.Index(
                        fields=["conversation"], name="notificatio_convers_8949ec_idx"
                    ),
                    models.Index(
                        fields=["message"], name="notificatio_message_7acb35_idx"
                    ),
                ],
            },
        ),
    ]
