# Generated by Django 5.0.10 on 2025-01-17 21:39

import django.utils.timezone
import model_utils.fields
import pgtrigger.compiler
import pgtrigger.migrations
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("baseapp_ai_langkit_chats", "0001_initial"),
    ]

    operations = [
        migrations.CreateModel(
            name="ChatIdentity",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "created",
                    model_utils.fields.AutoCreatedField(
                        default=django.utils.timezone.now, editable=False, verbose_name="created"
                    ),
                ),
                (
                    "modified",
                    model_utils.fields.AutoLastModifiedField(
                        default=django.utils.timezone.now, editable=False, verbose_name="modified"
                    ),
                ),
                ("name", models.CharField(max_length=255)),
                ("avatar", models.ImageField(blank=True, null=True, upload_to="chat-identities")),
                ("chat_intro_title", models.CharField(blank=True, max_length=255, null=True)),
                ("chat_intro_subtitle", models.CharField(blank=True, max_length=255, null=True)),
                (
                    "chat_fab_text",
                    models.CharField(
                        blank=True,
                        help_text="The Floating Action Button (FAB) text that will be displayed in the hover state of the Chat FAB.",
                        max_length=255,
                        null=True,
                    ),
                ),
                ("is_active", models.BooleanField(default=True)),
            ],
            options={
                "verbose_name_plural": "Chat Identities",
            },
        ),
        migrations.AlterModelOptions(
            name="chatsession",
            options={"get_latest_by": "created"},
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="chatidentity",
            trigger=pgtrigger.compiler.Trigger(
                name="ensure_single_active_chat_identity",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func="\n                BEGIN\n                    IF NEW.is_active THEN\n                        UPDATE baseapp_ai_langkit_chats_chatidentity SET is_active = FALSE WHERE id <> NEW.id AND is_active = TRUE;\n                    END IF;\n                    RETURN NEW;\n                END;\n                ",
                    hash="5c4054aca84a112fa0513f78bfd25cf159c168da",
                    operation="UPDATE OR INSERT",
                    pgid="pgtrigger_ensure_single_active_chat_identity_4cc24",
                    table="baseapp_ai_langkit_chats_chatidentity",
                    when="BEFORE",
                ),
            ),
        ),
    ]
