# Generated by Django 5.1.8 on 2025-06-03 19:06

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('contenttypes', '0002_remove_content_type_name'),
        ('extras', '0123_journalentry_kind_default'),
    ]

    operations = [
        migrations.CreateModel(
            name='Diagram',
            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()),
                ('description', models.CharField(blank=True)),
                ('cached_data', models.JSONField(blank=True, null=True)),
                ('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
            ],
            options={
                'verbose_name': 'Diagram',
                'verbose_name_plural': 'Diagrams',
            },
        ),
        migrations.CreateModel(
            name='DiagramAssociation',
            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)),
                ('assigned_object_id', models.PositiveBigIntegerField(blank=True, null=True)),
                ('coord_x', models.IntegerField(default=20)),
                ('coord_y', models.IntegerField(default=20)),
                ('assigned_object_type', models.ForeignKey(blank=True, limit_choices_to=models.Q(models.Q(models.Q(('app_label', 'dcim'), ('model', 'device')), models.Q(('app_label', 'circuits'), ('model', 'circuit')), models.Q(('app_label', 'netbox_diagram'), ('model', 'DiagramAssociation')), _connector='OR')), null=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='contenttypes.contenttype')),
                ('diagram', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='netbox_diagram.diagram')),
                ('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
            ],
            options={
                'verbose_name': 'Diagram Association',
                'verbose_name_plural': 'Diagram Assocations',
            },
        ),
        migrations.AddConstraint(
            model_name='diagram',
            constraint=models.UniqueConstraint(fields=('name',), name='netbox_diagram_diagram_unique__name', violation_error_message='The diagram name must be unique'),
        ),
        migrations.AddConstraint(
            model_name='diagramassociation',
            constraint=models.UniqueConstraint(fields=('diagram', 'assigned_object_type', 'assigned_object_id'), name='netbox_diagram_diagramassociation_unique_object_diagram_name', violation_error_message='An object can only be associated to a diagram once'),
        ),
    ]
