"""Initial migration for django_notify_hub."""
import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="Notification",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("title", models.JSONField(help_text='Localised title dict, e.g. {"en": "Hello"}', verbose_name="title")),
                ("body", models.JSONField(help_text='Localised body dict, e.g. {"en": "You have a new message."}', verbose_name="body")),
                ("data", models.JSONField(blank=True, default=dict, help_text="Arbitrary JSON payload.", verbose_name="metadata")),
                ("priority", models.CharField(
                    choices=[("low", "Low"), ("normal", "Normal"), ("high", "High"), ("critical", "Critical")],
                    default="normal", max_length=20, verbose_name="priority",
                )),
                ("channel", models.CharField(default="fcm", help_text="Delivery channel used (fcm, email, …).", max_length=50, verbose_name="channel")),
                ("status", models.CharField(
                    choices=[("pending", "Pending"), ("sent", "Sent"), ("failed", "Failed"), ("read", "Read")],
                    default="pending", max_length=20, verbose_name="status",
                )),
                ("is_read", models.BooleanField(default=False, verbose_name="read")),
                ("created_at", models.DateTimeField(default=django.utils.timezone.now, verbose_name="created at")),
                ("updated_at", models.DateTimeField(auto_now=True, verbose_name="updated at")),
                ("to_user", models.ForeignKey(
                    on_delete=django.db.models.deletion.CASCADE,
                    related_name="notifications",
                    to=settings.AUTH_USER_MODEL,
                    verbose_name="recipient",
                )),
            ],
            options={
                "verbose_name": "Notification",
                "verbose_name_plural": "Notifications",
                "ordering": ["-created_at"],
            },
        ),
        migrations.AddIndex(
            model_name="notification",
            index=models.Index(fields=["to_user", "is_read"], name="notify_user_read_idx"),
        ),
        migrations.AddIndex(
            model_name="notification",
            index=models.Index(fields=["to_user", "status"], name="notify_user_status_idx"),
        ),
        migrations.AddIndex(
            model_name="notification",
            index=models.Index(fields=["created_at"], name="notify_created_idx"),
        ),
    ]

