# Generated by Django 5.2.4 on 2025-08-31 22:58

from django.db import migrations, models
from django.db.models import Q
import core.fields
import utils.revision
from django.conf import settings
import django.db.models.deletion


def activate_default_package(apps, schema_editor):
    Package = apps.get_model("core", "Package")
    Package.objects.update(is_active=False)
    Package.objects.filter(name="arthexis").update(is_active=True)


class Migration(migrations.Migration):

    dependencies = [
        ("core", "0006_securitygroup_parent"),
    ]

    operations = [
        migrations.CreateModel(
            name="SigilRoot",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("is_seed_data", models.BooleanField(default=False, editable=False)),
                ("is_deleted", models.BooleanField(default=False, editable=False)),
                ("prefix", models.CharField(max_length=50, unique=True)),
                (
                    "context_type",
                    models.CharField(
                        max_length=20,
                        choices=[("config", "Configuration"), ("entity", "Entity")],
                    ),
                ),
                (
                    "content_type",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        to="contenttypes.contenttype",
                    ),
                ),
            ],
            options={
                "verbose_name": "Sigil Root",
                "verbose_name_plural": "Sigil Roots",
            },
        ),
        migrations.CreateModel(
            name="InviteLead",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("email", models.EmailField(max_length=254)),
                ("comment", models.TextField(blank=True)),
                (
                    "user",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                ("path", models.TextField(blank=True)),
                ("referer", models.TextField(blank=True)),
                ("user_agent", models.TextField(blank=True)),
                (
                    "ip_address",
                    models.GenericIPAddressField(blank=True, null=True),
                ),
                ("created_on", models.DateTimeField(auto_now_add=True)),
                ("is_seed_data", models.BooleanField(default=False, editable=False)),
                ("is_deleted", models.BooleanField(default=False, editable=False)),
            ],
            options={
                "verbose_name": "Invite Lead",
                "verbose_name_plural": "Invite Leads",
            },
        ),
        migrations.AlterField(
            model_name="odooprofile",
            name="host",
            field=core.fields.SigilShortAutoField(max_length=255),
        ),
        migrations.AlterField(
            model_name="odooprofile",
            name="database",
            field=core.fields.SigilShortAutoField(max_length=255),
        ),
        migrations.AlterField(
            model_name="odooprofile",
            name="username",
            field=core.fields.SigilShortAutoField(max_length=255),
        ),
        migrations.AlterField(
            model_name="odooprofile",
            name="password",
            field=core.fields.SigilShortAutoField(max_length=255),
        ),
        migrations.AlterField(
            model_name="releasemanager",
            name="pypi_username",
            field=core.fields.SigilShortAutoField(
                "PyPI username", blank=True, max_length=100
            ),
        ),
        migrations.AlterField(
            model_name="releasemanager",
            name="pypi_token",
            field=core.fields.SigilShortAutoField(
                "PyPI token", blank=True, max_length=200
            ),
        ),
        migrations.AlterField(
            model_name="releasemanager",
            name="github_token",
            field=core.fields.SigilShortAutoField(
                blank=True,
                help_text="Personal access token for GitHub operations. Used before the GITHUB_TOKEN environment variable.",
                max_length=200,
            ),
        ),
        migrations.AlterField(
            model_name="releasemanager",
            name="pypi_password",
            field=core.fields.SigilShortAutoField(
                "PyPI password", blank=True, max_length=200
            ),
        ),
        migrations.AlterField(
            model_name="releasemanager",
            name="pypi_url",
            field=core.fields.SigilShortAutoField(
                "PyPI URL", blank=True, max_length=200
            ),
        ),
        migrations.AlterField(
            model_name="emailinbox",
            name="username",
            field=core.fields.SigilShortAutoField(
                help_text="Login name for the mailbox", max_length=255
            ),
        ),
        migrations.AlterField(
            model_name="emailinbox",
            name="host",
            field=core.fields.SigilShortAutoField(
                help_text="Examples: Gmail IMAP 'imap.gmail.com', Gmail POP3 'pop.gmail.com', GoDaddy IMAP 'imap.secureserver.net', GoDaddy POP3 'pop.secureserver.net'",
                max_length=255,
            ),
        ),
        migrations.AlterField(
            model_name="emailinbox",
            name="password",
            field=core.fields.SigilShortAutoField(max_length=255),
        ),
        migrations.AlterField(
            model_name="emailinbox",
            name="protocol",
            field=core.fields.SigilShortAutoField(
                choices=[("imap", "IMAP"), ("pop3", "POP3")],
                default="imap",
                help_text="IMAP keeps emails on the server for access across devices; POP3 downloads messages to a single device and may remove them from the server",
                max_length=5,
            ),
        ),
        migrations.AlterField(
            model_name="package",
            name="name",
            field=models.CharField(default="arthexis", max_length=100, unique=True),
        ),
        migrations.AlterField(
            model_name="packagerelease",
            name="revision",
            field=models.CharField(
                blank=True,
                default=utils.revision.get_revision,
                editable=False,
                max_length=40,
            ),
        ),
        migrations.AddField(
            model_name="rfid",
            name="kind",
            field=models.CharField(
                default="CLASSIC",
                max_length=8,
                choices=[("CLASSIC", "MIFARE Classic"), ("NTAG215", "NTAG215")],
            ),
        ),
        migrations.AddField(
            model_name="package",
            name="is_active",
            field=models.BooleanField(
                default=False,
                help_text="Designates the active package for version comparisons",
            ),
        ),
        migrations.AddConstraint(
            model_name="package",
            constraint=models.UniqueConstraint(
                fields=("is_active",),
                condition=Q(is_active=True),
                name="unique_active_package",
            ),
        ),
        migrations.RunPython(activate_default_package, migrations.RunPython.noop),
    ]
