# Generated by Django 5.2.9 on 2026-01-04 22:49

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ("groups", "0002_initial"),
        ("nodes", "0011_netmessage_expires_at"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="FTPFolder",
            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_user_data", models.BooleanField(default=False, editable=False)),
                ("is_deleted", models.BooleanField(default=False, editable=False)),
                ("name", models.CharField(max_length=100)),
                ("path", models.CharField(max_length=500)),
                ("enabled", models.BooleanField(default=False)),
                (
                    "owner_permission",
                    models.CharField(
                        choices=[
                            ("read", "Read-only"),
                            ("write", "Read and write"),
                            ("admin", "Full control"),
                        ],
                        default="admin",
                        help_text="Permission granted to the owner for this folder.",
                        max_length=10,
                    ),
                ),
                (
                    "group_permission",
                    models.CharField(
                        choices=[
                            ("read", "Read-only"),
                            ("write", "Read and write"),
                            ("admin", "Full control"),
                        ],
                        default="read",
                        help_text="Permission granted to members of the security group.",
                        max_length=10,
                    ),
                ),
                (
                    "node",
                    models.ForeignKey(
                        blank=True,
                        help_text="Node that owns this folder. Leave blank to share globally.",
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="ftp_folders",
                        to="nodes.node",
                    ),
                ),
                (
                    "owner",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="owned_ftp_folders",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "security_group",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="ftp_folders",
                        to="groups.securitygroup",
                    ),
                ),
            ],
            options={
                "verbose_name": "FTP Folder",
                "verbose_name_plural": "FTP Folders",
                "unique_together": {("node", "name")},
            },
        ),
        migrations.CreateModel(
            name="FTPServer",
            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_user_data", models.BooleanField(default=False, editable=False)),
                ("is_deleted", models.BooleanField(default=False, editable=False)),
                (
                    "bind_address",
                    models.GenericIPAddressField(
                        default="0.0.0.0",
                        help_text="Interface to bind when starting the FTP server.",
                        unpack_ipv4=True,
                    ),
                ),
                (
                    "port",
                    models.PositiveIntegerField(
                        default=2121, help_text="TCP port where the FTP server listens."
                    ),
                ),
                (
                    "passive_ports",
                    models.CharField(
                        blank=True,
                        help_text="Optional passive port range, e.g. 60000-60010.",
                        max_length=50,
                    ),
                ),
                (
                    "enabled",
                    models.BooleanField(
                        default=False,
                        help_text="Toggle whether the FTP server should start.",
                    ),
                ),
                (
                    "node",
                    models.ForeignKey(
                        blank=True,
                        help_text="Node that should expose this FTP server configuration.",
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="ftp_servers",
                        to="nodes.node",
                    ),
                ),
            ],
            options={
                "verbose_name": "FTP Server",
                "verbose_name_plural": "FTP Servers",
                "constraints": [
                    models.UniqueConstraint(
                        condition=models.Q(("node__isnull", False)),
                        fields=("node",),
                        name="ftpserver_unique_node",
                    )
                ],
            },
        ),
    ]
