# Generated by Django 5.2.5 on 2025-12-02 12:06
import django.db.models.deletion
import netbox.models.deletion
import taggit.managers
import utilities.json
from django.db import migrations
from django.db import models


class Migration(migrations.Migration):
    dependencies = [
        ("extras", "0132_configcontextprofile"),
        ("ipfabric_netbox", "0021_update_transform_maps"),
    ]

    operations = [
        migrations.CreateModel(
            name="IPFabricEndpoint",
            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, unique=True)),
                ("description", models.TextField(blank=True, null=True)),
                ("endpoint", models.CharField(max_length=200, unique=True)),
                (
                    "tags",
                    taggit.managers.TaggableManager(
                        through="extras.TaggedItem", to="extras.Tag"
                    ),
                ),
            ],
            options={
                "verbose_name": "IP Fabric Endpoint",
                "verbose_name_plural": "IP Fabric Endpoints",
                "ordering": ("pk",),
            },
            bases=(netbox.models.deletion.DeleteMixin, models.Model),
        ),
        migrations.AddField(
            model_name="ipfabrictransformmap",
            name="source_endpoint",
            field=models.ForeignKey(
                null=True,
                on_delete=django.db.models.deletion.PROTECT,
                related_name="transform_maps",
                to="ipfabric_netbox.ipfabricendpoint",
            ),
        ),
        migrations.AddField(
            model_name="ipfabrictransformmap",
            name="parents",
            field=models.ManyToManyField(
                blank=True,
                help_text="Parent transform maps, for hierarchical organization during sync.",
                related_name="children",
                symmetrical=False,
                to="ipfabric_netbox.ipfabrictransformmap",
            ),
        ),
        migrations.CreateModel(
            name="IPFabricFilter",
            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, unique=True)),
                ("description", models.TextField(blank=True, null=True)),
                (
                    "endpoints",
                    models.ManyToManyField(
                        blank=True,
                        default=None,
                        related_name="filters",
                        to="ipfabric_netbox.ipfabricendpoint",
                    ),
                ),
                ("filter_type", models.CharField(max_length=10)),
                (
                    "syncs",
                    models.ManyToManyField(
                        blank=True,
                        default=None,
                        related_name="filters",
                        to="ipfabric_netbox.ipfabricsync",
                    ),
                ),
                (
                    "tags",
                    taggit.managers.TaggableManager(
                        through="extras.TaggedItem", to="extras.Tag"
                    ),
                ),
            ],
            options={
                "verbose_name": "IP Fabric Filter",
                "verbose_name_plural": "IP Fabric Filters",
                "ordering": ("pk",),
            },
            bases=(netbox.models.deletion.DeleteMixin, models.Model),
        ),
        migrations.CreateModel(
            name="IPFabricFilterExpression",
            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, unique=True)),
                ("description", models.TextField(blank=True, null=True)),
                ("expression", models.JSONField(default=list)),
                (
                    "filters",
                    models.ManyToManyField(
                        related_name="expressions", to="ipfabric_netbox.ipfabricfilter"
                    ),
                ),
                (
                    "tags",
                    taggit.managers.TaggableManager(
                        through="extras.TaggedItem", to="extras.Tag"
                    ),
                ),
            ],
            options={
                "verbose_name": "IP Fabric Filter Expression",
                "verbose_name_plural": "IP Fabric Filter Expressions",
                "ordering": ("pk",),
            },
            bases=(netbox.models.deletion.DeleteMixin, models.Model),
        ),
        # Make source_model nullable to allow reverse data migration
        migrations.AlterField(
            model_name="ipfabrictransformmap",
            name="source_model",
            field=models.CharField(max_length=50, null=True),
        ),
        # Extend size of name to allow for correction tags
        migrations.AlterField(
            model_name="ipfabrictransformmap",
            name="name",
            field=models.CharField(max_length=200),
        ),
    ]
