# Generated by Django 5.1.3 on 2026-05-24 16:53

import uuid
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("organizations", "0001_initial"),
        ("platform_modules", "0002_featureentitlement"),
        ("tenants", "0001_initial"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="Feature",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, db_index=True, verbose_name="created at"
                    ),
                ),
                ("updated_at", models.DateTimeField(auto_now=True, verbose_name="updated at")),
                (
                    "public_id",
                    models.UUIDField(
                        db_index=True,
                        default=uuid.uuid4,
                        editable=False,
                        unique=True,
                        verbose_name="public id",
                    ),
                ),
                (
                    "code",
                    models.CharField(
                        db_index=True,
                        help_text="Dotted code, e.g. 'chat.group_messaging'. Must be unique globally.",
                        max_length=80,
                        unique=True,
                        verbose_name="code",
                    ),
                ),
                ("label", models.CharField(blank=True, max_length=200, verbose_name="label")),
                (
                    "module_name",
                    models.CharField(
                        blank=True,
                        help_text="The module that provides this feature, e.g. 'chat'.",
                        max_length=80,
                        verbose_name="module",
                    ),
                ),
                (
                    "description",
                    models.TextField(blank=True, default="", verbose_name="description"),
                ),
            ],
            options={
                "verbose_name": "feature",
                "verbose_name_plural": "features",
                "ordering": ("module_name", "code"),
            },
        ),
        migrations.AlterModelOptions(
            name="featureentitlement",
            options={
                "ordering": ("module__name",),
                "verbose_name": "feature entitlement",
                "verbose_name_plural": "feature entitlements",
            },
        ),
        migrations.RemoveConstraint(
            model_name="featureentitlement",
            name="modules_feature_entitlement_unique_scope",
        ),
        migrations.RemoveIndex(
            model_name="featureentitlement",
            name="platform_mo_tenant__cbddff_idx",
        ),
        migrations.RemoveField(
            model_name="featureentitlement",
            name="feature_code",
        ),
        migrations.AddField(
            model_name="featureentitlement",
            name="features",
            field=models.ManyToManyField(
                blank=True,
                help_text="Select the features this entitlement grants access to.",
                related_name="entitlements",
                to="platform_modules.feature",
                verbose_name="features",
            ),
        ),
        migrations.AddIndex(
            model_name="featureentitlement",
            index=models.Index(fields=["tenant", "module"], name="platform_mo_tenant__432af5_idx"),
        ),
        migrations.AddConstraint(
            model_name="featureentitlement",
            constraint=models.UniqueConstraint(
                fields=("tenant", "module", "user"), name="modules_feature_entitlement_unique_scope"
            ),
        ),
    ]
