# Generated by Django 5.2.8 on 2026-01-23 17:07

import django.contrib.postgres.fields
import django.db.models.deletion
import netbox.models.deletion
import taggit.managers
import utilities.json
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
    dependencies = [
        ("contenttypes", "0002_remove_content_type_name"),
        ("extras", "0133_make_cf_minmax_decimal"),
        ("notices", "0004_outage_reported_at"),
        ("tenancy", "0020_remove_contactgroupmembership"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="MessageTemplate",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
                ("created", models.DateTimeField(auto_now_add=True, null=True)),
                ("last_updated", models.DateTimeField(auto_now=True, null=True)),
                (
                    "custom_field_data",
                    models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder),
                ),
                ("name", models.CharField(max_length=100)),
                ("slug", models.SlugField(unique=True)),
                ("description", models.TextField(blank=True)),
                ("event_type", models.CharField(max_length=20)),
                ("granularity", models.CharField(default="per_tenant", max_length=20)),
                ("subject_template", models.TextField()),
                ("body_template", models.TextField()),
                ("body_format", models.CharField(default="markdown", max_length=20)),
                ("css_template", models.TextField(blank=True)),
                ("headers_template", models.JSONField(blank=True, default=dict)),
                ("include_ical", models.BooleanField(default=False)),
                ("ical_template", models.TextField(blank=True)),
                (
                    "contact_priorities",
                    django.contrib.postgres.fields.ArrayField(
                        base_field=models.CharField(max_length=20), blank=True, default=list, size=None
                    ),
                ),
                ("is_base_template", models.BooleanField(default=False)),
                ("weight", models.IntegerField(default=1000)),
                (
                    "contact_roles",
                    models.ManyToManyField(blank=True, related_name="message_templates", to="tenancy.contactrole"),
                ),
                (
                    "extends",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="children",
                        to="notices.messagetemplate",
                    ),
                ),
                ("tags", taggit.managers.TaggableManager(through="extras.TaggedItem", to="extras.Tag")),
            ],
            options={
                "verbose_name": "Message Template",
                "verbose_name_plural": "Message Templates",
                "ordering": ["name"],
            },
            bases=(netbox.models.deletion.DeleteMixin, models.Model),
        ),
        migrations.CreateModel(
            name="PreparedMessage",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
                ("created", models.DateTimeField(auto_now_add=True, null=True)),
                ("last_updated", models.DateTimeField(auto_now=True, null=True)),
                (
                    "custom_field_data",
                    models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder),
                ),
                ("event_id", models.PositiveBigIntegerField(blank=True, null=True)),
                ("status", models.CharField(default="draft", max_length=20)),
                ("recipients", models.JSONField(default=list)),
                ("subject", models.CharField(max_length=255)),
                ("body_text", models.TextField()),
                ("body_html", models.TextField(blank=True)),
                ("headers", models.JSONField(default=dict)),
                ("css", models.TextField(blank=True)),
                ("ical_content", models.TextField(blank=True)),
                ("approved_at", models.DateTimeField(blank=True, null=True)),
                ("sent_at", models.DateTimeField(blank=True, null=True)),
                ("delivered_at", models.DateTimeField(blank=True, null=True)),
                ("viewed_at", models.DateTimeField(blank=True, null=True)),
                (
                    "approved_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="+",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "contacts",
                    models.ManyToManyField(blank=True, related_name="prepared_messages", to="tenancy.contact"),
                ),
                (
                    "event_content_type",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="+",
                        to="contenttypes.contenttype",
                    ),
                ),
                ("tags", taggit.managers.TaggableManager(through="extras.TaggedItem", to="extras.Tag")),
                (
                    "template",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="prepared_messages",
                        to="notices.messagetemplate",
                    ),
                ),
            ],
            options={
                "verbose_name": "Prepared Message",
                "verbose_name_plural": "Prepared Messages",
                "ordering": ["-created"],
            },
            bases=(netbox.models.deletion.DeleteMixin, models.Model),
        ),
        migrations.CreateModel(
            name="TemplateScope",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
                ("object_id", models.PositiveBigIntegerField(blank=True, null=True)),
                ("event_type", models.CharField(blank=True, max_length=20, null=True)),
                ("event_status", models.CharField(blank=True, max_length=50)),
                ("weight", models.IntegerField(default=1000)),
                (
                    "content_type",
                    models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="contenttypes.contenttype"),
                ),
                (
                    "template",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE, related_name="scopes", to="notices.messagetemplate"
                    ),
                ),
            ],
            options={
                "verbose_name": "Template Scope",
                "verbose_name_plural": "Template Scopes",
                "ordering": ["template", "-weight"],
                "constraints": [
                    models.UniqueConstraint(
                        fields=("template", "content_type", "object_id", "event_type", "event_status"),
                        name="unique_template_scope",
                    )
                ],
            },
        ),
    ]
