# Generated by Django 3.1.8 on 2021-04-22 19:40


# Disclaimer
# ----------
#
# Copyright (C) 2021 Helmholtz-Zentrum Hereon
# Copyright (C) 2020-2021 Helmholtz-Zentrum Geesthacht
#
# This file is part of django-academic-community and is released under the
# EUPL-1.2 license.
# See LICENSE in the root of the repository for full licensing details.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the EUROPEAN UNION PUBLIC LICENCE v. 1.2 or later
# as published by the European Commission.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# EUPL-1.2 license for more details.
#
# You should have received a copy of the EUPL-1.2 license along with this
# program. If not, see https://www.eupl.eu/.


import datetime

import django.db.models.deletion
import django.db.models.expressions
import djangocms_text_ckeditor.fields
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.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "subject",
                    models.CharField(
                        help_text="Subject of the mail", max_length=200
                    ),
                ),
                (
                    "reply_to",
                    models.EmailField(
                        help_text="The email address that the recipient should reply to.",
                        max_length=200,
                    ),
                ),
                (
                    "body",
                    djangocms_text_ckeditor.fields.HTMLField(
                        help_text="Email body"
                    ),
                ),
                (
                    "plain_text_body",
                    models.TextField(
                        blank=True,
                        help_text="Plain text without HTML. If null, it will be generated automatically.",
                        null=True,
                    ),
                ),
                (
                    "date_created",
                    models.DateTimeField(
                        auto_now_add=True, help_text="Sending date"
                    ),
                ),
                (
                    "unread",
                    models.BooleanField(
                        default=True,
                        help_text="Has the notification not yet been red by the user?",
                    ),
                ),
                (
                    "archived",
                    models.BooleanField(
                        default=False, help_text="Archive the notification."
                    ),
                ),
                (
                    "to_be_sent",
                    models.BooleanField(
                        default=True,
                        help_text="Shall the notification be sent via mail?",
                    ),
                ),
                (
                    "date_sent",
                    models.DateTimeField(
                        blank=True,
                        help_text="Time when the email has been sent",
                        null=True,
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        help_text="Recipient of the notification",
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "ordering": [
                    django.db.models.expressions.OrderBy(
                        django.db.models.expressions.F("date_created"),
                        descending=True,
                        nulls_last=True,
                    )
                ],
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="SystemNotification",
            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",
                    ),
                ),
            ],
            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="UserNotificationSettings",
            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=True,
                        help_text="Mark notifications as read when sent out via email.",
                        verbose_name="Mark as read when email has been sent",
                    ),
                ),
                (
                    "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": "User notification settings",
            },
        ),
        migrations.CreateModel(
            name="SystemNotificationSettings",
            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=True,
                        help_text="Mark notifications as read when sent out via email.",
                        verbose_name="Mark as read when email has been sent",
                    ),
                ),
                (
                    "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": "System notification settings",
            },
        ),
        migrations.CreateModel(
            name="OutgoingNotification",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "subject",
                    models.CharField(
                        help_text="Subject of the mail", max_length=200
                    ),
                ),
                (
                    "reply_to",
                    models.EmailField(
                        help_text="The email address that the recipient should reply to.",
                        max_length=200,
                    ),
                ),
                (
                    "body",
                    djangocms_text_ckeditor.fields.HTMLField(
                        help_text="Email body"
                    ),
                ),
                (
                    "plain_text_body",
                    models.TextField(
                        blank=True,
                        help_text="Plain text without HTML. If null, it will be generated automatically.",
                        null=True,
                    ),
                ),
                (
                    "date_created",
                    models.DateTimeField(
                        auto_now_add=True, help_text="Sending date"
                    ),
                ),
                (
                    "recipients",
                    models.ManyToManyField(
                        help_text="Recipient of the email.",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "sender",
                    models.ForeignKey(
                        help_text="Sender of the email",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="outgoing_notifications",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "ordering": [
                    django.db.models.expressions.OrderBy(
                        django.db.models.expressions.F("date_created"),
                        descending=True,
                        nulls_last=True,
                    )
                ],
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="UserNotification",
            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",
                    ),
                ),
                (
                    "outgoing_notification",
                    models.ForeignKey(
                        help_text="The base notification that generated this one.",
                        on_delete=django.db.models.deletion.CASCADE,
                        to="notifications.outgoingnotification",
                    ),
                ),
            ],
            options={
                "ordering": [
                    django.db.models.expressions.OrderBy(
                        django.db.models.expressions.F("date_created"),
                        descending=True,
                        nulls_last=True,
                    )
                ],
                "abstract": False,
            },
            bases=("notifications.notification",),
        ),
    ]
