# Generated by Django 3.2.7 on 2022-05-13 19:08

import datetime
import uuid

import django.db.models.deletion
import django.db.models.expressions
from django.conf import settings
from django.db import migrations, models


def set_mark_as_read_when_sent(apps, schema_editor):
    UserNotificationSettings = apps.get_model(
        "notifications", "UserNotificationSettings"
    )
    SystemNotificationSettings = apps.get_model(
        "notifications", "SystemNotificationSettings"
    )
    SystemNotificationSettings.objects.all().update(
        mark_as_read_when_sent=False
    )
    UserNotificationSettings.objects.all().update(mark_as_read_when_sent=False)


class Migration(migrations.Migration):

    dependencies = [
        ("e2ee", "0001_initial"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("chats", "0001_initial"),
        ("sessions", "0001_initial"),
        ("notifications", "0003_auto_20210630_1110"),
    ]

    operations = [
        migrations.CreateModel(
            name="ChatNotificationSettings",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "receive_mails",
                    models.BooleanField(
                        default=True,
                        help_text="Receive notifications via email.",
                    ),
                ),
                (
                    "mark_as_read_when_sent",
                    models.BooleanField(
                        default=False,
                        help_text="Mark notifications as read when sent out via email.",
                        verbose_name="Mark as read when email has been sent",
                    ),
                ),
                (
                    "push_notifications",
                    models.BooleanField(
                        default=True,
                        help_text="Enable push notifications for your devices.",
                    ),
                ),
                (
                    "display_notification_popups",
                    models.BooleanField(
                        default=True,
                        help_text="Use this setting to enable or disable small popups each time you get a notification.",
                    ),
                ),
                (
                    "collate_mails",
                    models.BooleanField(
                        default=False,
                        help_text="Collate notifications into one single notification",
                    ),
                ),
                (
                    "collation_interval",
                    models.DurationField(
                        default=datetime.timedelta(days=1),
                        help_text="Timespan for sending notifications.",
                    ),
                ),
                (
                    "include_bodies",
                    models.BooleanField(
                        default=True,
                        help_text="Include notification bodies in the email.",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        help_text="The user for whom this settings apply to.",
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name_plural": "Chat notification settings",
            },
        ),
        migrations.AddField(
            model_name="notification",
            name="encryption_key",
            field=models.ForeignKey(
                blank=True,
                help_text="The encryption key that has been used to encrypt the body of this notification.",
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                to="e2ee.encryptionkey",
            ),
        ),
        migrations.AddField(
            model_name="outgoingnotification",
            name="encryption_key",
            field=models.ForeignKey(
                blank=True,
                help_text="The encryption key that has been used to encrypt the body of this notification.",
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                to="e2ee.encryptionkey",
            ),
        ),
        migrations.AddField(
            model_name="notification",
            name="secret_uuid",
            field=models.UUIDField(
                default=uuid.uuid4,
                help_text="A field that is used to create unique webpush tokens.",
                null=True,
            ),
        ),
        migrations.AddField(
            model_name="systemnotificationsettings",
            name="display_notification_popups",
            field=models.BooleanField(
                default=True,
                help_text="Use this setting to enable or disable small popups each time you get a notification.",
            ),
        ),
        migrations.AddField(
            model_name="systemnotificationsettings",
            name="push_notifications",
            field=models.BooleanField(
                default=True,
                help_text="Enable push notifications for your devices.",
            ),
        ),
        migrations.AddField(
            model_name="usernotificationsettings",
            name="display_notification_popups",
            field=models.BooleanField(
                default=True,
                help_text="Use this setting to enable or disable small popups each time you get a notification.",
            ),
        ),
        migrations.AddField(
            model_name="usernotificationsettings",
            name="push_notifications",
            field=models.BooleanField(
                default=True,
                help_text="Enable push notifications for your devices.",
            ),
        ),
        migrations.AlterField(
            model_name="systemnotificationsettings",
            name="mark_as_read_when_sent",
            field=models.BooleanField(
                default=False,
                help_text="Mark notifications as read when sent out via email.",
                verbose_name="Mark as read when email has been sent",
            ),
        ),
        migrations.AlterField(
            model_name="usernotificationsettings",
            name="mark_as_read_when_sent",
            field=models.BooleanField(
                default=False,
                help_text="Mark notifications as read when sent out via email.",
                verbose_name="Mark as read when email has been sent",
            ),
        ),
        migrations.RunPython(
            set_mark_as_read_when_sent, migrations.RunPython.noop
        ),
        migrations.AlterField(
            model_name="notification",
            name="plain_text_body",
            field=models.TextField(
                blank=True,
                default="",
                help_text="Plain text without HTML. If null, it will be generated automatically.",
            ),
            preserve_default=False,
        ),
        migrations.AlterField(
            model_name="outgoingnotification",
            name="plain_text_body",
            field=models.TextField(
                blank=True,
                default="",
                help_text="Plain text without HTML. If null, it will be generated automatically.",
            ),
            preserve_default=False,
        ),
        migrations.CreateModel(
            name="NotificationSubscription",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("uuid", models.UUIDField(default=uuid.uuid4, unique=True)),
                ("browser", models.CharField(max_length=100)),
                (
                    "endpoint",
                    models.URLField(
                        help_text="The endpoint as provided by the subscription request",
                        max_length=600,
                    ),
                ),
                ("auth", models.CharField(max_length=100)),
                ("p256dh", models.CharField(max_length=100)),
                (
                    "push_error",
                    models.CharField(
                        blank=True,
                        help_text="Error during the last push event.",
                        max_length=1000,
                        null=True,
                    ),
                ),
                ("date_created", models.DateTimeField(auto_now_add=True)),
                ("last_login", models.DateTimeField()),
                (
                    "user",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="webpush_info",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "session",
                    models.ForeignKey(
                        blank=True,
                        help_text="The session for this subscription.",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="webpush_info",
                        to="sessions.session",
                    ),
                ),
            ],
        ),
        migrations.AddField(
            model_name="notification",
            name="closed_by",
            field=models.ForeignKey(
                blank=True,
                help_text="The subscription that closed this notification.",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                to="notifications.notificationsubscription",
            ),
        ),
        migrations.CreateModel(
            name="ChatNotification",
            fields=[
                (
                    "notification_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="notifications.notification",
                    ),
                ),
                (
                    "comment",
                    models.ForeignKey(
                        help_text="The comment that generated this notification.",
                        on_delete=django.db.models.deletion.CASCADE,
                        to="chats.comment",
                    ),
                ),
            ],
            options={
                "ordering": [
                    django.db.models.expressions.OrderBy(
                        django.db.models.expressions.F("date_created"),
                        descending=True,
                        nulls_last=True,
                    )
                ],
                "abstract": False,
            },
            bases=("notifications.notification",),
        ),
        migrations.CreateModel(
            name="ChannelNotificationSettings",
            fields=[
                (
                    "chatnotificationsettings_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="notifications.chatnotificationsettings",
                    ),
                ),
                (
                    "channel",
                    models.ForeignKey(
                        help_text="The channel that these settings apply for.",
                        on_delete=django.db.models.deletion.CASCADE,
                        to="chats.channel",
                    ),
                ),
            ],
            options={
                "verbose_name_plural": "Channel notification settings",
            },
            bases=("notifications.chatnotificationsettings",),
        ),
    ]
