# Generated by Django 5.1.4 on 2026-01-16 12:22

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


class Migration(migrations.Migration):
    dependencies = [
        ("accounts", "0001_initial"),
    ]

    operations = [
        migrations.CreateModel(
            name="APITokenPermission",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "resource",
                    models.CharField(
                        choices=[
                            ("cases", "Cases"),
                            ("laws", "Laws"),
                            ("courts", "Courts"),
                            ("lawbooks", "Law Books"),
                            ("references", "References"),
                            ("annotations", "Annotations"),
                        ],
                        help_text="The resource this permission applies to",
                        max_length=50,
                        verbose_name="Resource",
                    ),
                ),
                (
                    "action",
                    models.CharField(
                        choices=[
                            ("read", "Read"),
                            ("write", "Write"),
                            ("delete", "Delete"),
                        ],
                        help_text="The action allowed on this resource",
                        max_length=20,
                        verbose_name="Action",
                    ),
                ),
                (
                    "description",
                    models.TextField(
                        blank=True,
                        help_text="Optional description of what this permission allows",
                        verbose_name="Description",
                    ),
                ),
            ],
            options={
                "verbose_name": "API Token Permission",
                "verbose_name_plural": "API Token Permissions",
                "ordering": ["resource", "action"],
            },
        ),
        migrations.CreateModel(
            name="APITokenPermissionGroup",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        help_text="Unique name for this permission group",
                        max_length=100,
                        unique=True,
                        verbose_name="Name",
                    ),
                ),
                (
                    "description",
                    models.TextField(
                        blank=True,
                        help_text="Description of what this permission group allows",
                        verbose_name="Description",
                    ),
                ),
                (
                    "is_default",
                    models.BooleanField(
                        default=False,
                        help_text="Whether this is the default permission group for new tokens",
                        verbose_name="Is Default",
                    ),
                ),
                (
                    "created",
                    models.DateTimeField(auto_now_add=True, verbose_name="Created"),
                ),
                (
                    "updated",
                    models.DateTimeField(auto_now=True, verbose_name="Updated"),
                ),
            ],
            options={
                "verbose_name": "API Token Permission Group",
                "verbose_name_plural": "API Token Permission Groups",
                "ordering": ["name"],
            },
        ),
        migrations.RenameIndex(
            model_name="apitoken",
            new_name="accounts_ap_user_id_42f198_idx",
            old_name="accounts_ap_user_id_ac6ac5_idx",
        ),
        migrations.RenameIndex(
            model_name="apitoken",
            new_name="accounts_ap_expires_46b4e5_idx",
            old_name="accounts_ap_expires_e66c1e_idx",
        ),
        migrations.AlterField(
            model_name="apitoken",
            name="scopes",
            field=models.JSONField(
                blank=True,
                default=list,
                help_text="Deprecated: Use permission_group instead. List of scopes this token has access to",
                verbose_name="Scopes",
            ),
        ),
        migrations.AlterUniqueTogether(
            name="apitokenpermission",
            unique_together={("resource", "action")},
        ),
        migrations.AddField(
            model_name="apitokenpermissiongroup",
            name="permissions",
            field=models.ManyToManyField(
                blank=True,
                help_text="Permissions included in this group",
                related_name="permission_groups",
                to="accounts.apitokenpermission",
                verbose_name="Permissions",
            ),
        ),
        migrations.AddField(
            model_name="apitoken",
            name="permission_group",
            field=models.ForeignKey(
                blank=True,
                help_text="The permission group assigned to this token (defines what resources it can access)",
                null=True,
                on_delete=django.db.models.deletion.PROTECT,
                related_name="tokens",
                to="accounts.apitokenpermissiongroup",
                verbose_name="Permission Group",
            ),
        ),
    ]
