# Generated by Django 5.2.8 on 2025-11-11 15:28

import uuid

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


class Migration(migrations.Migration):
    dependencies = [
        ("vibes_auth", "0005_alter_user_groups"),
    ]

    operations = [
        migrations.CreateModel(
            name="ChatThread",
            fields=[
                (
                    "uuid",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="unique id is used to surely identify any database object",
                        primary_key=True,
                        serialize=False,
                        verbose_name="unique id",
                    ),
                ),
                (
                    "is_active",
                    models.BooleanField(
                        default=True,
                        help_text="if set to false, this object can't be seen by users without needed permission",
                        verbose_name="is active",
                    ),
                ),
                (
                    "created",
                    django_extensions.db.fields.CreationDateTimeField(
                        auto_now_add=True,
                        help_text="when the object first appeared on the database",
                        verbose_name="created",
                    ),
                ),
                (
                    "modified",
                    django_extensions.db.fields.ModificationDateTimeField(
                        auto_now=True,
                        help_text="when the object was last modified",
                        verbose_name="modified",
                    ),
                ),
                (
                    "email",
                    models.EmailField(
                        blank=True,
                        default="",
                        help_text="For anonymous threads",
                        max_length=254,
                    ),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[("open", "Open"), ("closed", "Closed")],
                        default="open",
                        max_length=16,
                    ),
                ),
                (
                    "last_message_at",
                    models.DateTimeField(default=django.utils.timezone.now),
                ),
                ("attributes", models.JSONField(blank=True, default=dict)),
                (
                    "assigned_to",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="assigned_chat_threads",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="chat_threads",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "Chat thread",
                "verbose_name_plural": "Chat threads",
                "ordering": ("-modified",),
            },
        ),
        migrations.CreateModel(
            name="ChatMessage",
            fields=[
                (
                    "uuid",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="unique id is used to surely identify any database object",
                        primary_key=True,
                        serialize=False,
                        verbose_name="unique id",
                    ),
                ),
                (
                    "is_active",
                    models.BooleanField(
                        default=True,
                        help_text="if set to false, this object can't be seen by users without needed permission",
                        verbose_name="is active",
                    ),
                ),
                (
                    "created",
                    django_extensions.db.fields.CreationDateTimeField(
                        auto_now_add=True,
                        help_text="when the object first appeared on the database",
                        verbose_name="created",
                    ),
                ),
                (
                    "modified",
                    django_extensions.db.fields.ModificationDateTimeField(
                        auto_now=True,
                        help_text="when the object was last modified",
                        verbose_name="modified",
                    ),
                ),
                (
                    "sender_type",
                    models.CharField(
                        choices=[
                            ("user", "User"),
                            ("staff", "Staff"),
                            ("system", "System"),
                        ],
                        max_length=16,
                    ),
                ),
                ("text", models.TextField()),
                ("sent_at", models.DateTimeField(default=django.utils.timezone.now)),
                ("attributes", models.JSONField(blank=True, default=dict)),
                (
                    "sender_user",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="chat_messages",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "thread",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="messages",
                        to="vibes_auth.chatthread",
                    ),
                ),
            ],
            options={
                "verbose_name": "Chat message",
                "verbose_name_plural": "Chat messages",
                "ordering": ("sent_at", "uuid"),
            },
        ),
        migrations.AddIndex(
            model_name="chatthread",
            index=models.Index(
                fields=["status", "modified"], name="chatthread_status_mod_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="chatthread",
            index=models.Index(
                fields=["assigned_to", "status"], name="chatthread_assigned_status_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="chatthread",
            index=models.Index(fields=["user"], name="chatthread_user_idx"),
        ),
        migrations.AddIndex(
            model_name="chatthread",
            index=models.Index(fields=["email"], name="chatthread_email_idx"),
        ),
        migrations.AddIndex(
            model_name="chatmessage",
            index=models.Index(
                fields=["thread", "sent_at"], name="chatmessage_thread_sent_idx"
            ),
        ),
    ]
