# Generated by Discord Obfuscate on 2026-02-19

# Django
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
    initial = True

    operations = [
        migrations.CreateModel(
            name="General",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
            ],
            options={
                "permissions": (("basic_access", "Can access this app"),),
                "managed": False,
                "default_permissions": (),
            },
        ),
        migrations.CreateModel(
            name="DiscordRoleColorRule",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        help_text="Rule name shown in admin.",
                        max_length=100,
                    ),
                ),
                (
                    "pattern",
                    models.CharField(
                        help_text="Role name pattern. Use * as a wildcard.",
                        max_length=150,
                    ),
                ),
                (
                    "enabled",
                    models.BooleanField(
                        default=True,
                        help_text="Enable automatic color assignment for this rule.",
                    ),
                ),
                (
                    "case_sensitive",
                    models.BooleanField(
                        default=False,
                        help_text="Match role names with case sensitivity.",
                    ),
                ),
                (
                    "priority",
                    models.PositiveIntegerField(
                        default=100,
                        help_text="Lower numbers run first when multiple rules match.",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={
                "verbose_name": "Discord Role Color Rule",
                "verbose_name_plural": "Discord Role Color Rules",
                "ordering": ["priority", "name"],
            },
        ),
        migrations.CreateModel(
            name="DiscordObfuscateConfig",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "sync_on_save",
                    models.BooleanField(
                        default=True,
                        help_text="Queue a role rename task when a config is saved in admin.",
                    ),
                ),
                (
                    "default_opt_out",
                    models.BooleanField(
                        default=False,
                        help_text="Default opt-out for newly created entries.",
                    ),
                ),
                (
                    "default_use_random_key",
                    models.BooleanField(
                        default=False,
                        help_text="Default random key setting for newly created entries.",
                    ),
                ),
                (
                    "default_random_key_rotate_name",
                    models.BooleanField(
                        default=True,
                        help_text="Default rotate-name setting for new random-key entries.",
                    ),
                ),
                (
                    "default_random_key_rotate_position",
                    models.BooleanField(
                        default=True,
                        help_text="Default rotate-position setting for new random-key entries.",
                    ),
                ),
                (
                    "default_obfuscation_type",
                    models.CharField(
                        choices=[
                            ("sha256_hex", "SHA256 + hex"),
                            ("sha256_base32", "SHA256 + base32"),
                            ("blake2s_hex", "BLAKE2s + hex"),
                            ("blake2s_base32", "BLAKE2s + base32"),
                        ],
                        default="sha256_base32",
                        help_text="Default obfuscation type for new entries.",
                        max_length=32,
                    ),
                ),
                (
                    "default_divider_characters",
                    models.CharField(
                        blank=True,
                        default="",
                        help_text="Default divider characters for new entries.",
                        max_length=64,
                    ),
                ),
                (
                    "default_min_chars_before_divider",
                    models.PositiveIntegerField(
                        default=0,
                        help_text="Default minimum chars before divider for new entries.",
                    ),
                ),
                (
                    "random_key_rotation_enabled",
                    models.BooleanField(
                        default=False,
                        help_text="Enable periodic rotation of random obfuscation keys.",
                    ),
                ),
                (
                    "role_color_rule_sync_enabled",
                    models.BooleanField(
                        default=False,
                        help_text="Enable periodic sync for role color rules.",
                    ),
                ),
                (
                    "periodic_sync_enabled",
                    models.BooleanField(
                        default=False,
                        help_text="Enable periodic full sync of roles via Celery beat.",
                    ),
                ),
            ],
            options={
                "verbose_name": "Discord Obfuscate Config",
            },
        ),
        migrations.CreateModel(
            name="DiscordRoleObfuscation",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "opt_out",
                    models.BooleanField(
                        default=True,
                        help_text="When enabled, the original group name is used.",
                    ),
                ),
                (
                    "obfuscation_type",
                    models.CharField(
                        choices=[
                            ("sha256_hex", "SHA256 + hex"),
                            ("sha256_base32", "SHA256 + base32"),
                            ("blake2s_hex", "BLAKE2s + hex"),
                            ("blake2s_base32", "BLAKE2s + base32"),
                        ],
                        default="sha256_base32",
                        max_length=32,
                    ),
                ),
                (
                    "obfuscation_format",
                    models.CharField(
                        blank=True,
                        default="",
                        help_text="Format string using {hash8}, {hash12}, {hash16}.",
                        max_length=120,
                    ),
                ),
                (
                    "divider_characters",
                    models.CharField(
                        blank=True,
                        default="",
                        help_text="Comma-separated list of divider characters.",
                        max_length=64,
                    ),
                ),
                (
                    "min_chars_before_divider",
                    models.PositiveIntegerField(
                        default=0,
                        help_text="Minimum number of characters before a divider is used.",
                    ),
                ),
                (
                    "custom_name",
                    models.CharField(
                        blank=True,
                        default="",
                        help_text="If set, overrides the obfuscation method.",
                        max_length=100,
                    ),
                ),
                (
                    "use_random_key",
                    models.BooleanField(
                        default=False,
                        help_text=(
                            "If enabled, obfuscation uses a random key instead of the group name. "
                            "Rotation tasks only apply to entries with this enabled."
                        ),
                    ),
                ),
                (
                    "random_key",
                    models.CharField(
                        blank=True,
                        default="",
                        help_text="Random 16-character key used for obfuscation when enabled.",
                        max_length=16,
                    ),
                ),
                (
                    "random_key_rotate_name",
                    models.BooleanField(
                        default=True,
                        help_text=(
                            "Allow the rotation task to rename this role. "
                            "Only applies when random key mode is enabled."
                        ),
                    ),
                ),
                (
                    "random_key_rotate_position",
                    models.BooleanField(
                        default=True,
                        help_text=(
                            "Allow the rotation task to reposition this role. "
                            "Only applies when random key mode is enabled."
                        ),
                    ),
                ),
                (
                    "role_color",
                    models.CharField(
                        blank=True,
                        default="",
                        help_text="Optional role color in hex (#RRGGBB).",
                        max_length=7,
                    ),
                ),
                (
                    "role_id",
                    models.BigIntegerField(
                        blank=True,
                        help_text="Cached Discord role ID for rename operations.",
                        null=True,
                    ),
                ),
                (
                    "last_obfuscated_name",
                    models.CharField(
                        blank=True,
                        default="",
                        max_length=100,
                        verbose_name="Obfuscated Name",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "group",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="discord_obfuscation",
                        to="auth.group",
                    ),
                ),
            ],
            options={
                "verbose_name": "Discord Role Obfuscation",
                "verbose_name_plural": "Discord Role Obfuscations",
                "ordering": ["group__name"],
            },
        ),
        migrations.CreateModel(
            name="DiscordRoleColorAssignment",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("role_id", models.BigIntegerField()),
                ("role_name", models.CharField(max_length=100)),
                ("color", models.CharField(max_length=7)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "rule",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="assignments",
                        to="discord_obfuscate.discordrolecolorrule",
                    ),
                ),
            ],
            options={
                "verbose_name": "Discord Role Color Assignment",
                "verbose_name_plural": "Discord Role Color Assignments",
                "ordering": ["rule", "role_name"],
            },
        ),
        migrations.AddConstraint(
            model_name="discordrolecolorassignment",
            constraint=models.UniqueConstraint(
                fields=("role_id",), name="unique_role_color_role"
            ),
        ),
        migrations.AddConstraint(
            model_name="discordrolecolorassignment",
            constraint=models.UniqueConstraint(
                fields=("color",), name="unique_role_color_value"
            ),
        ),
    ]
