# Generated by Django 5.2.9 on 2026-02-04 18:46

import django.db.models.deletion
import netbox.models.deletion
import taggit.managers
import utilities.json
from django.db import migrations, models


class Migration(migrations.Migration):
    initial = True

    dependencies = [
        ("extras", "0134_owner"),
        ("ipam", "0086_gfk_indexes"),
    ]

    operations = [
        migrations.CreateModel(
            name="RIRAccount",
            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)),
                ("api_key", models.CharField(max_length=255)),
                ("api_url", models.URLField(blank=True, default="")),
                ("org_handle", models.CharField(blank=True, default="", max_length=50)),
                ("is_active", models.BooleanField(default=True)),
                ("last_sync", models.DateTimeField(blank=True, null=True)),
                (
                    "rir",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE, related_name="rir_accounts", to="ipam.rir"
                    ),
                ),
                ("tags", taggit.managers.TaggableManager(through="extras.TaggedItem", to="extras.Tag")),
            ],
            options={
                "ordering": ["rir", "name"],
            },
            bases=(netbox.models.deletion.DeleteMixin, models.Model),
        ),
        migrations.CreateModel(
            name="RIROrganization",
            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),
                ),
                ("handle", models.CharField(max_length=50, unique=True)),
                ("name", models.CharField(max_length=255)),
                ("street_address", models.TextField(blank=True, default="")),
                ("city", models.CharField(blank=True, default="", max_length=100)),
                ("state_province", models.CharField(blank=True, default="", max_length=100)),
                ("postal_code", models.CharField(blank=True, default="", max_length=20)),
                ("country", models.CharField(blank=True, default="", max_length=2)),
                ("raw_data", models.JSONField(blank=True, default=dict)),
                ("last_synced", models.DateTimeField(blank=True, null=True)),
                (
                    "account",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="organizations",
                        to="netbox_rir_manager.riraccount",
                    ),
                ),
                ("tags", taggit.managers.TaggableManager(through="extras.TaggedItem", to="extras.Tag")),
            ],
            options={
                "ordering": ["handle"],
            },
            bases=(netbox.models.deletion.DeleteMixin, models.Model),
        ),
        migrations.CreateModel(
            name="RIRNetwork",
            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),
                ),
                ("handle", models.CharField(max_length=50, unique=True)),
                ("net_name", models.CharField(max_length=100)),
                ("raw_data", models.JSONField(blank=True, default=dict)),
                ("last_synced", models.DateTimeField(blank=True, null=True)),
                (
                    "account",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="networks",
                        to="netbox_rir_manager.riraccount",
                    ),
                ),
                (
                    "aggregate",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="rir_networks",
                        to="ipam.aggregate",
                    ),
                ),
                (
                    "prefix",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="rir_networks",
                        to="ipam.prefix",
                    ),
                ),
                ("tags", taggit.managers.TaggableManager(through="extras.TaggedItem", to="extras.Tag")),
                (
                    "organization",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="networks",
                        to="netbox_rir_manager.rirorganization",
                    ),
                ),
            ],
            options={
                "ordering": ["handle"],
            },
            bases=(netbox.models.deletion.DeleteMixin, models.Model),
        ),
        migrations.CreateModel(
            name="RIRContact",
            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),
                ),
                ("handle", models.CharField(max_length=50, unique=True)),
                ("contact_type", models.CharField(max_length=20)),
                ("first_name", models.CharField(blank=True, default="", max_length=100)),
                ("last_name", models.CharField(max_length=100)),
                ("company_name", models.CharField(blank=True, default="", max_length=255)),
                ("email", models.EmailField(blank=True, default="", max_length=254)),
                ("phone", models.CharField(blank=True, default="", max_length=50)),
                ("raw_data", models.JSONField(blank=True, default=dict)),
                ("last_synced", models.DateTimeField(blank=True, null=True)),
                (
                    "account",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="contacts",
                        to="netbox_rir_manager.riraccount",
                    ),
                ),
                ("tags", taggit.managers.TaggableManager(through="extras.TaggedItem", to="extras.Tag")),
                (
                    "organization",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="contacts",
                        to="netbox_rir_manager.rirorganization",
                    ),
                ),
            ],
            options={
                "ordering": ["handle"],
            },
            bases=(netbox.models.deletion.DeleteMixin, models.Model),
        ),
        migrations.CreateModel(
            name="RIRSyncLog",
            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),
                ),
                ("operation", models.CharField(max_length=50)),
                ("object_type", models.CharField(max_length=50)),
                ("object_handle", models.CharField(max_length=100)),
                ("status", models.CharField(max_length=20)),
                ("message", models.TextField(blank=True, default="")),
                (
                    "account",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="sync_logs",
                        to="netbox_rir_manager.riraccount",
                    ),
                ),
                ("tags", taggit.managers.TaggableManager(through="extras.TaggedItem", to="extras.Tag")),
            ],
            options={
                "ordering": ["-created"],
            },
            bases=(netbox.models.deletion.DeleteMixin, models.Model),
        ),
        migrations.AddConstraint(
            model_name="riraccount",
            constraint=models.UniqueConstraint(fields=("rir", "name"), name="unique_rir_account_name"),
        ),
    ]
