# Generated by Django 4.2.24 on 2025-12-31 06:23

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


class Migration(migrations.Migration):

    dependencies = [
        ("auth", "0012_alter_user_first_name_max_length"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("conversations", "0013_alter_chatmessage_backend_lock_and_more"),
    ]

    operations = [
        migrations.AddField(
            model_name="conversation",
            name="downvote_count",
            field=models.IntegerField(
                default=0,
                help_text="Cached count of downvotes for this conversation/thread",
            ),
        ),
        migrations.AddField(
            model_name="conversation",
            name="upvote_count",
            field=models.IntegerField(
                default=0,
                help_text="Cached count of upvotes for this conversation/thread",
            ),
        ),
        migrations.CreateModel(
            name="ConversationVote",
            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)),
                (
                    "vote_type",
                    models.CharField(
                        choices=[("upvote", "Upvote"), ("downvote", "Downvote")],
                        help_text="Type of vote (upvote or downvote)",
                        max_length=16,
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, help_text="Timestamp when the vote was cast"
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the vote was last changed",
                    ),
                ),
                (
                    "conversation",
                    models.ForeignKey(
                        help_text="The conversation/thread being voted on",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="votes",
                        to="conversations.conversation",
                    ),
                ),
                (
                    "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={
                "permissions": (
                    ("permission_conversationvote", "permission conversationvote"),
                    ("create_conversationvote", "create conversationvote"),
                    ("read_conversationvote", "read conversationvote"),
                    ("update_conversationvote", "update conversationvote"),
                    ("remove_conversationvote", "delete conversationvote"),
                ),
            },
        ),
        migrations.CreateModel(
            name="ConversationVoteUserObjectPermission",
            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.conversationvote",
                    ),
                ),
                (
                    "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="ConversationVoteGroupObjectPermission",
            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.conversationvote",
                    ),
                ),
                (
                    "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="conversationvote",
            index=models.Index(
                fields=["conversation", "vote_type"],
                name="conversatio_convers_b43061_idx",
            ),
        ),
        migrations.AddIndex(
            model_name="conversationvote",
            index=models.Index(
                fields=["creator"], name="conversatio_creator_03f75f_idx"
            ),
        ),
        migrations.AddConstraint(
            model_name="conversationvote",
            constraint=models.UniqueConstraint(
                fields=("conversation", "creator"),
                name="one_vote_per_user_per_conversation",
            ),
        ),
    ]
