# Generated by Django 4.2.24 on 2025-12-27 06:52

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


class Migration(migrations.Migration):

    dependencies = [
        ("conversations", "0013_alter_chatmessage_backend_lock_and_more"),
        ("documents", "0027_alter_document_backend_lock_and_more"),
        ("agents", "0007_alter_agentactionresult_backend_lock_and_more"),
    ]

    operations = [
        migrations.RemoveConstraint(
            model_name="agentactionresult",
            name="unique_corpus_action_document_result",
        ),
        migrations.AddField(
            model_name="agentactionresult",
            name="triggering_conversation",
            field=models.ForeignKey(
                blank=True,
                help_text="Thread that triggered this agent action (for thread-based triggers)",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="triggered_agent_action_results",
                to="conversations.conversation",
            ),
        ),
        migrations.AddField(
            model_name="agentactionresult",
            name="triggering_message",
            field=models.ForeignKey(
                blank=True,
                help_text="Message that triggered this agent action (for NEW_MESSAGE trigger)",
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="triggered_agent_action_results",
                to="conversations.chatmessage",
            ),
        ),
        migrations.AlterField(
            model_name="agentactionresult",
            name="document",
            field=models.ForeignKey(
                blank=True,
                help_text="The document this action was run on (null for thread-based actions)",
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="agent_action_results",
                to="documents.document",
            ),
        ),
        migrations.AddIndex(
            model_name="agentactionresult",
            index=models.Index(
                fields=["corpus_action", "triggering_conversation"],
                name="agents_agen_corpus__36d781_idx",
            ),
        ),
        migrations.AddConstraint(
            model_name="agentactionresult",
            constraint=models.UniqueConstraint(
                condition=models.Q(("document__isnull", False)),
                fields=("corpus_action", "document"),
                name="unique_corpus_action_document_result",
            ),
        ),
        migrations.AddConstraint(
            model_name="agentactionresult",
            constraint=models.UniqueConstraint(
                condition=models.Q(("triggering_conversation__isnull", False)),
                fields=(
                    "corpus_action",
                    "triggering_conversation",
                    "triggering_message",
                ),
                name="unique_corpus_action_thread_result",
            ),
        ),
    ]
