# Generated by Django 3.2.13 on 2022-04-25 13:07

import django.core.validators
import django.db.models.deletion
import django_inet.models
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
    dependencies = [
        ("reversion", "0002_add_index_on_version_for_content_type_and_db"),
        ("peeringdb_server", "0083_auto_20220412_1554"),
    ]

    operations = [
        migrations.CreateModel(
            name="DataChangeWatchedObject",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "ref_tag",
                    models.CharField(choices=[("net", "Network")], max_length=255),
                ),
                ("object_id", models.PositiveIntegerField()),
                (
                    "created",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="User started watching this object at this time",
                    ),
                ),
                (
                    "last_notified",
                    models.DateTimeField(
                        blank=True,
                        help_text="Last time user was notified about changes to this object",
                        null=True,
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="watched_objects",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "Data Change Watched Object",
                "verbose_name_plural": "Data Change Watched Object",
                "db_table": "peeringdb_data_change_watch",
            },
        ),
        migrations.CreateModel(
            name="DataChangeNotificationQueue",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "watched_ref_tag",
                    models.CharField(choices=[("net", "Network")], max_length=255),
                ),
                ("watched_object_id", models.PositiveIntegerField()),
                ("ref_tag", models.CharField(max_length=255)),
                ("object_id", models.PositiveIntegerField()),
                (
                    "reason",
                    models.CharField(
                        blank=True,
                        help_text="Reason for notification",
                        max_length=255,
                        null=True,
                    ),
                ),
                (
                    "action",
                    models.CharField(
                        choices=[
                            ("add", "Added"),
                            ("modify", "Updated"),
                            ("delete", "Deleted"),
                        ],
                        max_length=255,
                    ),
                ),
                (
                    "source",
                    models.CharField(
                        help_text="Source of automated update", max_length=32
                    ),
                ),
                ("created", models.DateTimeField(auto_now_add=True)),
                (
                    "version_after",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="data_change_notification_after",
                        to="reversion.version",
                    ),
                ),
                (
                    "version_before",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="data_change_notification_before",
                        to="reversion.version",
                    ),
                ),
            ],
            options={
                "verbose_name": "Data Change Notification Queue",
                "verbose_name_plural": "Data Change Notification Queue",
                "db_table": "peeringdb_data_change_notify",
            },
        ),
        migrations.CreateModel(
            name="DataChangeEmail",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("email", models.EmailField(max_length=254)),
                ("content", models.TextField()),
                ("subject", models.CharField(max_length=255)),
                ("created", models.DateTimeField(auto_now_add=True)),
                ("sent", models.DateTimeField(blank=True, null=True)),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="data_change_emails",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "watched_object",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="data_change_emails",
                        to="peeringdb_server.datachangewatchedobject",
                    ),
                ),
            ],
            options={
                "verbose_name": "Data Change Email",
                "verbose_name_plural": "Data Change Emails",
                "db_table": "peeringdb_data_change_email",
            },
        ),
        migrations.AddIndex(
            model_name="datachangewatchedobject",
            index=models.Index(
                fields=["ref_tag", "object_id"], name="data_change_watch_obj"
            ),
        ),
        migrations.AlterUniqueTogether(
            name="datachangewatchedobject",
            unique_together={("user", "ref_tag", "object_id")},
        ),
        migrations.AddIndex(
            model_name="datachangenotificationqueue",
            index=models.Index(
                fields=["watched_ref_tag", "watched_object_id"],
                name="data_change_notify_watch",
            ),
        ),
        migrations.AddIndex(
            model_name="datachangenotificationqueue",
            index=models.Index(
                fields=["ref_tag", "object_id"], name="data_change_notify_target"
            ),
        ),
    ]
