# Generated by Codex for netbox_unifi_sync

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="GlobalSyncSettings",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("singleton_key", models.CharField(default="default", max_length=32, unique=True)),
                ("enabled", models.BooleanField(default=True)),
                ("tenant_name", models.CharField(help_text="Mandatory import tenant name in NetBox", max_length=100)),
                ("default_vrf_name", models.CharField(blank=True, max_length=100)),
                (
                    "vrf_mode",
                    models.CharField(
                        choices=[("none", "None"), ("existing", "Existing"), ("create", "Create")],
                        default="existing",
                        max_length=16,
                    ),
                ),
                ("serial_mode", models.CharField(default="mac", max_length=24)),
                ("default_site", models.CharField(blank=True, max_length=100)),
                (
                    "tag_strategy",
                    models.CharField(
                        choices=[("append", "Append"), ("replace", "Replace"), ("none", "None")],
                        default="append",
                        max_length=16,
                    ),
                ),
                ("default_tags", models.JSONField(blank=True, default=list)),
                (
                    "netbox_roles",
                    models.JSONField(default=dict, help_text="Map UniFi role keys to NetBox device role names"),
                ),
                ("sync_interfaces", models.BooleanField(default=True)),
                ("sync_vlans", models.BooleanField(default=True)),
                ("sync_wlans", models.BooleanField(default=True)),
                ("sync_cables", models.BooleanField(default=True)),
                ("sync_stale_cleanup", models.BooleanField(default=True)),
                ("dhcp_auto_discover", models.BooleanField(default=True)),
                ("dhcp_writeback_enabled", models.BooleanField(default=False)),
                ("cleanup_enabled", models.BooleanField(default=False)),
                ("cleanup_grace_days", models.PositiveIntegerField(default=30)),
                ("schedule_enabled", models.BooleanField(default=False)),
                ("sync_interval_minutes", models.PositiveIntegerField(default=60)),
                ("dry_run_default", models.BooleanField(default=False)),
                ("verify_ssl_default", models.BooleanField(default=True)),
                ("request_timeout", models.PositiveIntegerField(default=15)),
                ("http_retries", models.PositiveIntegerField(default=3)),
                ("retry_backoff_base", models.FloatField(default=1.0)),
                ("retry_backoff_max", models.FloatField(default=30.0)),
                ("max_controller_threads", models.PositiveIntegerField(default=5)),
                ("max_site_threads", models.PositiveIntegerField(default=8)),
                ("max_device_threads", models.PositiveIntegerField(default=8)),
                ("rate_limit_per_second", models.PositiveIntegerField(default=0)),
                ("specs_auto_refresh", models.BooleanField(default=False)),
                ("specs_include_store", models.BooleanField(default=False)),
                ("specs_refresh_timeout", models.PositiveIntegerField(default=45)),
                ("specs_store_timeout", models.PositiveIntegerField(default=15)),
                ("specs_store_max_workers", models.PositiveIntegerField(default=8)),
                ("specs_write_cache", models.BooleanField(default=False)),
                ("updated", models.DateTimeField(auto_now=True)),
            ],
            options={
                "verbose_name": "UniFi sync settings",
                "ordering": ("singleton_key",),
                "permissions": (
                    ("run_sync", "Can trigger UniFi sync"),
                    ("run_cleanup", "Can trigger UniFi cleanup"),
                    ("test_controller", "Can test UniFi controller connectivity"),
                ),
            },
        ),
        migrations.CreateModel(
            name="PluginAuditEvent",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("created", models.DateTimeField(auto_now_add=True)),
                ("action", models.CharField(max_length=64)),
                ("status", models.CharField(choices=[("success", "Success"), ("error", "Error")], max_length=16)),
                ("target", models.CharField(blank=True, max_length=128)),
                ("message", models.CharField(max_length=255)),
                ("details", models.JSONField(blank=True, default=dict)),
                (
                    "actor",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="netbox_unifi_sync_audit_events",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={"ordering": ("-created",)},
        ),
        migrations.CreateModel(
            name="SchedulerState",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("key", models.CharField(default="default", max_length=32, unique=True)),
                ("last_auto_sync", models.DateTimeField(blank=True, null=True)),
                ("updated", models.DateTimeField(auto_now=True)),
            ],
        ),
        migrations.CreateModel(
            name="SpecsCacheMetadata",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("source", models.CharField(max_length=64, unique=True)),
                ("etag", models.CharField(blank=True, max_length=255)),
                ("last_refresh", models.DateTimeField(blank=True, null=True)),
                ("success", models.BooleanField(default=False)),
                ("details", models.JSONField(blank=True, default=dict)),
            ],
            options={"ordering": ("source",)},
        ),
        migrations.CreateModel(
            name="SyncRun",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("pending", "Pending"),
                            ("running", "Running"),
                            ("success", "Success"),
                            ("failed", "Failed"),
                            ("dry_run", "Dry run"),
                            ("skipped", "Skipped"),
                        ],
                        default="pending",
                        max_length=24,
                    ),
                ),
                ("trigger", models.CharField(default="manual", max_length=32)),
                ("dry_run", models.BooleanField(default=False)),
                ("cleanup_requested", models.BooleanField(default=False)),
                ("job_id", models.CharField(blank=True, max_length=128)),
                ("created", models.DateTimeField(auto_now_add=True)),
                ("started", models.DateTimeField(blank=True, null=True)),
                ("completed", models.DateTimeField(blank=True, null=True)),
                ("duration_ms", models.PositiveIntegerField(default=0)),
                ("controllers_total", models.PositiveIntegerField(default=0)),
                ("sites_total", models.PositiveIntegerField(default=0)),
                ("devices_total", models.PositiveIntegerField(default=0)),
                ("summary", models.CharField(blank=True, max_length=255)),
                ("error", models.TextField(blank=True)),
                ("counters", models.JSONField(blank=True, default=dict)),
                ("details", models.JSONField(blank=True, default=dict)),
                (
                    "requested_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="netbox_unifi_sync_runs",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={"ordering": ("-created",)},
        ),
        migrations.CreateModel(
            name="UnifiController",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("name", models.CharField(max_length=100, unique=True)),
                ("base_url", models.URLField(max_length=255, unique=True)),
                ("enabled", models.BooleanField(default=True)),
                (
                    "auth_mode",
                    models.CharField(
                        choices=[("api_key", "API key"), ("login", "Login")],
                        default="api_key",
                        max_length=16,
                    ),
                ),
                ("api_key_ref", models.CharField(blank=True, help_text="Use env:VAR_NAME or file:/path", max_length=255)),
                ("api_key_header", models.CharField(default="X-API-KEY", max_length=64)),
                ("username_ref", models.CharField(blank=True, help_text="Use env:VAR_NAME or file:/path", max_length=255)),
                ("password_ref", models.CharField(blank=True, help_text="Use env:VAR_NAME or file:/path", max_length=255)),
                ("mfa_secret_ref", models.CharField(blank=True, help_text="Use env:VAR_NAME or file:/path", max_length=255)),
                ("verify_ssl", models.BooleanField(default=True)),
                ("request_timeout", models.PositiveIntegerField(blank=True, null=True)),
                ("http_retries", models.PositiveIntegerField(blank=True, null=True)),
                ("retry_backoff_base", models.FloatField(blank=True, null=True)),
                ("retry_backoff_max", models.FloatField(blank=True, null=True)),
                ("notes", models.TextField(blank=True)),
                ("last_tested", models.DateTimeField(blank=True, null=True)),
                ("last_test_status", models.CharField(blank=True, max_length=16)),
                ("last_test_error", models.TextField(blank=True)),
                ("created", models.DateTimeField(auto_now_add=True)),
                ("updated", models.DateTimeField(auto_now=True)),
            ],
            options={"ordering": ("name",)},
        ),
        migrations.CreateModel(
            name="SiteMapping",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("unifi_site", models.CharField(max_length=100)),
                ("netbox_site", models.CharField(max_length=100)),
                ("enabled", models.BooleanField(default=True)),
                (
                    "controller",
                    models.ForeignKey(
                        blank=True,
                        help_text="Leave empty to apply mapping globally",
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="site_mappings",
                        to="netbox_unifi_sync.unificontroller",
                    ),
                ),
            ],
            options={"ordering": ("unifi_site",)},
        ),
        migrations.AlterUniqueTogether(
            name="sitemapping",
            unique_together={("controller", "unifi_site")},
        ),
    ]
