# Generated by Django 5.2.5 on 2025-10-21 10: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):
    dependencies = [
        ("dcim", "0215_rackreservation_status"),
        ("extras", "0133_make_cf_minmax_decimal"),
        ("netbox_authorized_keys", "0005_alter_authorizedkey_options"),
        ("virtualization", "0048_populate_mac_addresses"),
    ]

    operations = [
        migrations.CreateModel(
            name="Credential",
            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),
                ),
                ("credential_type", models.CharField(default="password", max_length=70)),
                ("username", models.CharField(max_length=255)),
                ("owner", models.CharField(max_length=255)),
                ("key_fingerprint", models.TextField(blank=True, default="")),
                ("storage_location", models.CharField(blank=True, default="", max_length=255)),
                ("description", models.CharField(blank=True, default="", max_length=255)),
                ("comments", models.TextField(blank=True, default="")),
                ("tags", taggit.managers.TaggableManager(through="extras.TaggedItem", to="extras.Tag")),
            ],
            options={
                "verbose_name": "Credential",
                "verbose_name_plural": "Credentials",
                "ordering": ["id"],
            },
            bases=(netbox.models.deletion.DeleteMixin, models.Model),
        ),
        migrations.CreateModel(
            name="CredentialDevice",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
                (
                    "credential",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE, to="netbox_authorized_keys.credential"
                    ),
                ),
                ("device", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="dcim.device")),
            ],
            options={
                "ordering": ["id"],
                "unique_together": {("credential", "device")},
            },
        ),
        migrations.AddField(
            model_name="credential",
            name="devices",
            field=models.ManyToManyField(
                blank=True,
                related_name="credentials",
                through="netbox_authorized_keys.CredentialDevice",
                to="dcim.device",
            ),
        ),
        migrations.CreateModel(
            name="CredentialVirtualMachine",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
                (
                    "credential",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE, to="netbox_authorized_keys.credential"
                    ),
                ),
                (
                    "virtual_machine",
                    models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="virtualization.virtualmachine"),
                ),
            ],
            options={
                "ordering": ["id"],
                "unique_together": {("credential", "virtual_machine")},
            },
        ),
        migrations.AddField(
            model_name="credential",
            name="virtual_machines",
            field=models.ManyToManyField(
                blank=True,
                related_name="credentials",
                through="netbox_authorized_keys.CredentialVirtualMachine",
                to="virtualization.virtualmachine",
            ),
        ),
    ]
