# Generated by ChatGPT on 2026-03-05

import uuid

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


class Migration(migrations.Migration):

    dependencies = [
        ("core", "0035_conversationevent_adapterhealthevent"),
    ]

    operations = [
        migrations.AddField(
            model_name="memoryitem",
            name="confidence_score",
            field=models.FloatField(
                default=0.5,
                help_text="Confidence score for this memory (0.0-1.0).",
            ),
        ),
        migrations.AddField(
            model_name="memoryitem",
            name="expires_at",
            field=models.DateTimeField(
                blank=True,
                help_text="Optional expiry timestamp for stale memory decay.",
                null=True,
            ),
        ),
        migrations.AddField(
            model_name="memoryitem",
            name="last_verified_at",
            field=models.DateTimeField(
                blank=True,
                help_text="Last operator verification timestamp.",
                null=True,
            ),
        ),
        migrations.AddField(
            model_name="memoryitem",
            name="person",
            field=models.ForeignKey(
                blank=True,
                help_text=(
                    "Optional person this memory is about for person-centric recall."
                ),
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="memory_items",
                to="core.person",
            ),
        ),
        migrations.AddField(
            model_name="memoryitem",
            name="provenance",
            field=models.JSONField(
                blank=True,
                default=dict,
                help_text=(
                    "Source metadata for this memory (agent/tool/message references)."
                ),
            ),
        ),
        migrations.CreateModel(
            name="KnowledgeArticle",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                ("title", models.CharField(max_length=255)),
                ("slug", models.SlugField(max_length=255)),
                ("markdown", models.TextField(blank=True, default="")),
                ("tags", models.JSONField(blank=True, default=list)),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("draft", "Draft"),
                            ("published", "Published"),
                            ("archived", "Archived"),
                        ],
                        default="draft",
                        max_length=16,
                    ),
                ),
                ("owner_identifier", models.CharField(blank=True, default="", max_length=255)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "related_task",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="knowledge_articles",
                        to="core.derivedtask",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="knowledge_articles",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "indexes": [
                    models.Index(
                        fields=["user", "status", "updated_at"],
                        name="core_knowl_user_id_331625_idx",
                    ),
                    models.Index(
                        fields=["related_task", "updated_at"],
                        name="core_knowl_related_cf6071_idx",
                    ),
                ],
                "constraints": [
                    models.UniqueConstraint(
                        fields=("user", "slug"),
                        name="unique_knowledge_article_slug_per_user",
                    )
                ],
            },
        ),
        migrations.CreateModel(
            name="MCPToolAuditLog",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                ("tool_name", models.CharField(max_length=255)),
                ("request_args", models.JSONField(blank=True, default=dict)),
                ("response_meta", models.JSONField(blank=True, default=dict)),
                ("ok", models.BooleanField(default=True)),
                ("error", models.TextField(blank=True, default="")),
                ("duration_ms", models.PositiveIntegerField(default=0)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "user",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="mcp_tool_audit_logs",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "indexes": [
                    models.Index(
                        fields=["tool_name", "created_at"],
                        name="core_mcpau_tool_na_2db9d7_idx",
                    ),
                    models.Index(
                        fields=["user", "created_at"],
                        name="core_mcpau_user_id_4a55f1_idx",
                    ),
                    models.Index(
                        fields=["ok", "created_at"],
                        name="core_mcpau_ok_1f5c91_idx",
                    ),
                ]
            },
        ),
        migrations.CreateModel(
            name="MemoryChangeRequest",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "action",
                    models.CharField(
                        choices=[
                            ("create", "Create"),
                            ("update", "Update"),
                            ("delete", "Delete"),
                        ],
                        max_length=16,
                    ),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("pending", "Pending"),
                            ("approved", "Approved"),
                            ("rejected", "Rejected"),
                            ("applied", "Applied"),
                        ],
                        default="pending",
                        max_length=16,
                    ),
                ),
                ("proposed_memory_kind", models.CharField(blank=True, default="", max_length=16)),
                ("proposed_content", models.JSONField(blank=True, default=dict)),
                ("proposed_confidence_score", models.FloatField(blank=True, null=True)),
                ("proposed_expires_at", models.DateTimeField(blank=True, null=True)),
                ("reason", models.TextField(blank=True, default="")),
                ("requested_by_identifier", models.CharField(blank=True, default="", max_length=255)),
                ("reviewed_by_identifier", models.CharField(blank=True, default="", max_length=255)),
                ("reviewed_at", models.DateTimeField(blank=True, null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "conversation",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="memory_change_requests",
                        to="core.workspaceconversation",
                    ),
                ),
                (
                    "memory",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="change_requests",
                        to="core.memoryitem",
                    ),
                ),
                (
                    "person",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="memory_change_requests",
                        to="core.person",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="memory_change_requests",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "indexes": [
                    models.Index(
                        fields=["user", "status", "created_at"],
                        name="core_memor_user_id_31963a_idx",
                    ),
                    models.Index(
                        fields=["memory", "created_at"],
                        name="core_memor_memory__1b9d7e_idx",
                    ),
                ]
            },
        ),
        migrations.CreateModel(
            name="MemorySourceReference",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("source_label", models.CharField(blank=True, default="", max_length=255)),
                ("source_uri", models.CharField(blank=True, default="", max_length=1024)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "memory",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="source_references",
                        to="core.memoryitem",
                    ),
                ),
                (
                    "message",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="memory_source_references",
                        to="core.message",
                    ),
                ),
                (
                    "message_event",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="memory_source_references",
                        to="core.messageevent",
                    ),
                ),
                (
                    "source_request",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="memory_source_references",
                        to="core.airequest",
                    ),
                ),
            ],
            options={
                "indexes": [
                    models.Index(
                        fields=["memory", "created_at"],
                        name="core_memor_memory__92752b_idx",
                    ),
                    models.Index(fields=["source_uri"], name="core_memor_source__5bb587_idx"),
                ]
            },
        ),
        migrations.CreateModel(
            name="TaskArtifactLink",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                ("kind", models.CharField(default="note", max_length=64)),
                ("uri", models.CharField(blank=True, default="", max_length=1024)),
                ("path", models.CharField(blank=True, default="", max_length=1024)),
                ("summary", models.TextField(blank=True, default="")),
                ("created_by_identifier", models.CharField(blank=True, default="", max_length=255)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "task",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="artifact_links",
                        to="core.derivedtask",
                    ),
                ),
            ],
            options={
                "indexes": [
                    models.Index(
                        fields=["task", "created_at"],
                        name="core_taskar_task_id_cf5572_idx",
                    ),
                    models.Index(
                        fields=["kind", "created_at"],
                        name="core_taskar_kind_5dbab7_idx",
                    ),
                ]
            },
        ),
        migrations.CreateModel(
            name="KnowledgeRevision",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("revision", models.PositiveIntegerField()),
                ("author_tool", models.CharField(blank=True, default="", max_length=255)),
                ("author_identifier", models.CharField(blank=True, default="", max_length=255)),
                ("summary", models.TextField(blank=True, default="")),
                ("markdown", models.TextField(blank=True, default="")),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "article",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="revisions",
                        to="core.knowledgearticle",
                    ),
                ),
            ],
            options={
                "ordering": ["article", "revision"],
                "constraints": [
                    models.UniqueConstraint(
                        fields=("article", "revision"),
                        name="unique_knowledge_revision_per_article",
                    )
                ],
            },
        ),
        migrations.AddIndex(
            model_name="memoryitem",
            index=models.Index(
                fields=["user", "status", "updated_at"],
                name="core_mem_user_stat_upd_idx",
            ),
        ),
        migrations.AddIndex(
            model_name="memoryitem",
            index=models.Index(
                fields=["user", "person", "status", "updated_at"],
                name="core_mem_user_pers_stat_idx",
            ),
        ),
        migrations.AddIndex(
            model_name="memoryitem",
            index=models.Index(
                fields=["user", "conversation", "status", "updated_at"],
                name="core_mem_user_conv_stat_idx",
            ),
        ),
    ]
