# Generated by Django 4.2.24 on 2025-10-27 04:20

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),
        ("auth", "0012_alter_user_first_name_max_length"),
        ("corpuses", "0022_add_agent_instructions"),
        ("conversations", "0006_messagevote_userreputation_and_more"),
    ]

    operations = [
        migrations.CreateModel(
            name="CorpusModerator",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("backend_lock", models.BooleanField(default=False)),
                ("is_public", models.BooleanField(default=False)),
                ("created", models.DateTimeField(auto_now_add=True)),
                ("modified", models.DateTimeField(auto_now=True)),
                (
                    "permissions",
                    models.JSONField(
                        default=list,
                        help_text="List of permission strings (e.g., ['lock_threads', 'pin_threads'])",
                    ),
                ),
                (
                    "assigned_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="When moderator permissions were assigned",
                    ),
                ),
                (
                    "assigned_by",
                    models.ForeignKey(
                        blank=True,
                        help_text="Who assigned these moderator permissions",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="assigned_moderators",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "corpus",
                    models.ForeignKey(
                        help_text="The corpus being moderated",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="moderators",
                        to="corpuses.corpus",
                    ),
                ),
                (
                    "creator",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        help_text="The user who is a moderator",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="moderated_corpuses",
                        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={
                "permissions": (
                    ("permission_corpusmoderator", "permission corpusmoderator"),
                    ("create_corpusmoderator", "create corpusmoderator"),
                    ("read_corpusmoderator", "read corpusmoderator"),
                    ("update_corpusmoderator", "update corpusmoderator"),
                    ("remove_corpusmoderator", "delete corpusmoderator"),
                ),
            },
        ),
        migrations.AddField(
            model_name="conversation",
            name="is_locked",
            field=models.BooleanField(
                default=False,
                help_text="Whether the thread is locked (prevents new messages)",
            ),
        ),
        migrations.AddField(
            model_name="conversation",
            name="is_pinned",
            field=models.BooleanField(
                default=False,
                help_text="Whether the thread is pinned (appears at top of list)",
            ),
        ),
        migrations.AddField(
            model_name="conversation",
            name="locked_at",
            field=models.DateTimeField(
                blank=True, help_text="Timestamp when the thread was locked", null=True
            ),
        ),
        migrations.AddField(
            model_name="conversation",
            name="locked_by",
            field=models.ForeignKey(
                blank=True,
                help_text="Moderator who locked the thread",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="locked_conversations",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AddField(
            model_name="conversation",
            name="pinned_at",
            field=models.DateTimeField(
                blank=True, help_text="Timestamp when the thread was pinned", null=True
            ),
        ),
        migrations.AddField(
            model_name="conversation",
            name="pinned_by",
            field=models.ForeignKey(
                blank=True,
                help_text="Moderator who pinned the thread",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="pinned_conversations",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.CreateModel(
            name="ModerationAction",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("backend_lock", models.BooleanField(default=False)),
                ("is_public", models.BooleanField(default=False)),
                ("created", models.DateTimeField(auto_now_add=True)),
                ("modified", models.DateTimeField(auto_now=True)),
                (
                    "action_type",
                    models.CharField(
                        choices=[
                            ("lock_thread", "Lock Thread"),
                            ("unlock_thread", "Unlock Thread"),
                            ("pin_thread", "Pin Thread"),
                            ("unpin_thread", "Unpin Thread"),
                            ("delete_thread", "Delete Thread"),
                            ("restore_thread", "Restore Thread"),
                            ("delete_message", "Delete Message"),
                            ("restore_message", "Restore Message"),
                        ],
                        help_text="Type of moderation action taken",
                        max_length=32,
                    ),
                ),
                (
                    "reason",
                    models.TextField(
                        blank=True,
                        help_text="Optional reason for the moderation action",
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, help_text="When the action was taken"
                    ),
                ),
                (
                    "conversation",
                    models.ForeignKey(
                        blank=True,
                        help_text="The conversation that was moderated",
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="moderation_actions",
                        to="conversations.conversation",
                    ),
                ),
                (
                    "creator",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "message",
                    models.ForeignKey(
                        blank=True,
                        help_text="The message that was moderated",
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="moderation_actions",
                        to="conversations.chatmessage",
                    ),
                ),
                (
                    "moderator",
                    models.ForeignKey(
                        help_text="Moderator who took this action",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="moderation_actions_taken",
                        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={
                "ordering": ["-created_at"],
                "permissions": (
                    ("permission_moderationaction", "permission moderationaction"),
                    ("create_moderationaction", "create moderationaction"),
                    ("read_moderationaction", "read moderationaction"),
                ),
            },
        ),
        migrations.CreateModel(
            name="CorpusModeratorUserObjectPermission",
            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="conversations.corpusmoderator",
                    ),
                ),
                (
                    "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,
            },
        ),
        migrations.CreateModel(
            name="CorpusModeratorGroupObjectPermission",
            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="conversations.corpusmoderator",
                    ),
                ),
                (
                    "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,
            },
        ),
        migrations.CreateModel(
            name="ModerationActionUserObjectPermission",
            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="conversations.moderationaction",
                    ),
                ),
                (
                    "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="ModerationActionGroupObjectPermission",
            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="conversations.moderationaction",
                    ),
                ),
                (
                    "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="moderationaction",
            index=models.Index(
                fields=["conversation"], name="conversatio_convers_3050ee_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="moderationaction",
            index=models.Index(
                fields=["message"], name="conversatio_message_0b4080_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="moderationaction",
            index=models.Index(
                fields=["moderator"], name="conversatio_moderat_ddce29_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="moderationaction",
            index=models.Index(
                fields=["action_type"], name="conversatio_action__57b228_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="moderationaction",
            index=models.Index(
                fields=["created_at"], name="conversatio_created_f21cc2_idx"
            ),
        ),
        migrations.AlterUniqueTogether(
            name="corpusmoderatoruserobjectpermission",
            unique_together={("user", "permission", "content_object")},
        ),
        migrations.AlterUniqueTogether(
            name="corpusmoderatorgroupobjectpermission",
            unique_together={("group", "permission", "content_object")},
        ),
        migrations.AddIndex(
            model_name="corpusmoderator",
            index=models.Index(
                fields=["corpus", "user"], name="conversatio_corpus__f5a4cf_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="corpusmoderator",
            index=models.Index(fields=["user"], name="conversatio_user_id_22d6dc_idx"),
        ),
        migrations.AddConstraint(
            model_name="corpusmoderator",
            constraint=models.UniqueConstraint(
                fields=("corpus", "user"), name="one_moderator_per_user_per_corpus"
            ),
        ),
    ]
