# Generated by Django 4.2.24 on 2025-11-10 13:15

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


class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("documents", "0022_alter_documentanalysisrow_options_and_more"),
        ("auth", "0012_alter_user_first_name_max_length"),
        ("corpuses", "0023_corpusengagementmetrics"),
    ]

    operations = [
        migrations.CreateModel(
            name="CorpusFolder",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        help_text="Folder name (not full path)", max_length=255
                    ),
                ),
                ("description", models.TextField(blank=True, default="")),
                (
                    "color",
                    models.CharField(
                        blank=True,
                        default="#05313d",
                        help_text="Hex color for UI display",
                        max_length=7,
                    ),
                ),
                (
                    "icon",
                    models.CharField(
                        blank=True,
                        default="folder",
                        help_text="Icon identifier for UI",
                        max_length=50,
                    ),
                ),
                (
                    "tags",
                    models.JSONField(
                        blank=True,
                        default=list,
                        help_text="List of tags for categorization",
                    ),
                ),
                ("created", models.DateTimeField(default=django.utils.timezone.now)),
                ("modified", models.DateTimeField(default=django.utils.timezone.now)),
                (
                    "corpus",
                    models.ForeignKey(
                        help_text="Parent corpus this folder belongs to",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="folders",
                        to="corpuses.corpus",
                    ),
                ),
                (
                    "creator",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "parent",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="children",
                        to="corpuses.corpusfolder",
                        verbose_name="parent",
                    ),
                ),
            ],
            options={
                "ordering": ("name",),
                "permissions": (
                    ("permission_corpusfolder", "permission corpusfolder"),
                    ("publish_corpusfolder", "publish corpusfolder"),
                    ("create_corpusfolder", "create corpusfolder"),
                    ("read_corpusfolder", "read corpusfolder"),
                    ("update_corpusfolder", "update corpusfolder"),
                    ("remove_corpusfolder", "delete corpusfolder"),
                ),
            },
        ),
        migrations.CreateModel(
            name="CorpusDocumentFolder",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "added_to_folder",
                    models.DateTimeField(
                        default=django.utils.timezone.now,
                        help_text="When document was added to this folder",
                    ),
                ),
                (
                    "corpus",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="document_folder_assignments",
                        to="corpuses.corpus",
                    ),
                ),
                (
                    "document",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="corpus_folder_assignments",
                        to="documents.document",
                    ),
                ),
                (
                    "folder",
                    models.ForeignKey(
                        blank=True,
                        help_text="Folder containing this document. Null = root of corpus.",
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="document_assignments",
                        to="corpuses.corpusfolder",
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="CorpusFolderUserObjectPermission",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "content_object",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="corpuses.corpusfolder",
                    ),
                ),
                (
                    "permission",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="auth.permission",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "abstract": False,
                "unique_together": {("user", "permission", "content_object")},
            },
        ),
        migrations.CreateModel(
            name="CorpusFolderGroupObjectPermission",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "content_object",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="corpuses.corpusfolder",
                    ),
                ),
                (
                    "group",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE, to="auth.group"
                    ),
                ),
                (
                    "permission",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="auth.permission",
                    ),
                ),
            ],
            options={
                "abstract": False,
                "unique_together": {("group", "permission", "content_object")},
            },
        ),
        migrations.AddIndex(
            model_name="corpusfolder",
            index=models.Index(
                fields=["corpus", "name"], name="corpuses_co_corpus__833e3d_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="corpusfolder",
            index=models.Index(
                fields=["creator"], name="corpuses_co_creator_b472ce_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="corpusfolder",
            index=models.Index(
                fields=["corpus", "parent"], name="corpuses_co_corpus__7db971_idx"
            ),
        ),
        migrations.AddConstraint(
            model_name="corpusfolder",
            constraint=models.UniqueConstraint(
                fields=("corpus", "parent", "name"),
                name="unique_folder_name_per_parent",
            ),
        ),
        migrations.AddIndex(
            model_name="corpusdocumentfolder",
            index=models.Index(
                fields=["corpus", "folder"], name="corpuses_co_corpus__077fea_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="corpusdocumentfolder",
            index=models.Index(
                fields=["document", "corpus"], name="corpuses_co_documen_818193_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="corpusdocumentfolder",
            index=models.Index(
                fields=["folder"], name="corpuses_co_folder__b77f19_idx"
            ),
        ),
        migrations.AddConstraint(
            model_name="corpusdocumentfolder",
            constraint=models.UniqueConstraint(
                fields=("document", "corpus"), name="unique_document_folder_per_corpus"
            ),
        ),
    ]
