# Generated by Django 4.2.24 on 2025-12-31 22:17

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


class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("corpuses", "0033_remove_corpusquery"),
    ]

    operations = [
        migrations.CreateModel(
            name="CorpusCategory",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("backend_lock", models.BooleanField(db_index=True, default=False)),
                ("is_public", models.BooleanField(default=False)),
                ("created", models.DateTimeField(auto_now_add=True)),
                ("modified", models.DateTimeField(auto_now=True)),
                ("name", models.CharField(max_length=255, unique=True)),
                ("description", models.TextField(blank=True, default="")),
                (
                    "icon",
                    models.CharField(
                        default="folder",
                        help_text="Lucide icon name (e.g., 'scroll', 'file-text', 'building-2')",
                        max_length=100,
                    ),
                ),
                (
                    "color",
                    models.CharField(
                        default="#3B82F6",
                        help_text="Hex color code for the category badge",
                        max_length=7,
                    ),
                ),
                (
                    "sort_order",
                    models.IntegerField(
                        default=0, help_text="Order in which categories appear in UI"
                    ),
                ),
                (
                    "creator",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "user_lock",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="locked_%(class)s_objects",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "Corpus Category",
                "verbose_name_plural": "Corpus Categories",
                "ordering": ["sort_order", "name"],
            },
        ),
        # NOTE: CorpusQuery and related permission models were already dropped
        # by migration 0033_remove_corpusquery using RunSQL. We removed the
        # Django model operations here to avoid "constraint not found" errors.
        migrations.AddField(
            model_name="corpus",
            name="categories",
            field=models.ManyToManyField(
                blank=True,
                help_text="Categories assigned to this corpus for discovery filtering",
                related_name="corpuses",
                to="corpuses.corpuscategory",
            ),
        ),
    ]
