# Generated by Django 5.2.10 on 2026-03-15 23:59

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="AgentTaskModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "request_id",
                    models.CharField(
                        db_index=True,
                        help_text="Stable request trace id",
                        max_length=64,
                        unique=True,
                    ),
                ),
                (
                    "schema_version",
                    models.CharField(default="v1", help_text="Schema version", max_length=16),
                ),
                (
                    "task_domain",
                    models.CharField(
                        choices=[
                            ("research", "RESEARCH"),
                            ("monitoring", "MONITORING"),
                            ("decision", "DECISION"),
                            ("execution", "EXECUTION"),
                            ("ops", "OPS"),
                        ],
                        db_index=True,
                        help_text="Task domain: research/monitoring/decision/execution/ops",
                        max_length=20,
                    ),
                ),
                ("task_type", models.CharField(help_text="Task subtype", max_length=100)),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("draft", "DRAFT"),
                            ("context_ready", "CONTEXT_READY"),
                            ("proposal_generated", "PROPOSAL_GENERATED"),
                            ("awaiting_approval", "AWAITING_APPROVAL"),
                            ("approved", "APPROVED"),
                            ("rejected", "REJECTED"),
                            ("executing", "EXECUTING"),
                            ("completed", "COMPLETED"),
                            ("failed", "FAILED"),
                            ("needs_human", "NEEDS_HUMAN"),
                            ("cancelled", "CANCELLED"),
                        ],
                        db_index=True,
                        default="draft",
                        help_text="Current task status",
                        max_length=30,
                    ),
                ),
                ("input_payload", models.JSONField(default=dict, help_text="JSON input payload")),
                (
                    "current_step",
                    models.CharField(
                        blank=True, help_text="Current step key", max_length=100, null=True
                    ),
                ),
                (
                    "last_error",
                    models.JSONField(blank=True, help_text="Structured error payload", null=True),
                ),
                (
                    "requires_human",
                    models.BooleanField(
                        default=False, help_text="Whether human intervention is needed"
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "created_by",
                    models.ForeignKey(
                        blank=True,
                        help_text="User id if authenticated",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="agent_tasks",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "db_table": "agent_task",
                "ordering": ["-created_at"],
            },
        ),
        migrations.CreateModel(
            name="AgentProposalModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "request_id",
                    models.CharField(
                        db_index=True, help_text="Trace id", max_length=64, unique=True
                    ),
                ),
                (
                    "schema_version",
                    models.CharField(default="v1", help_text="Schema version", max_length=16),
                ),
                (
                    "proposal_type",
                    models.CharField(
                        help_text="Type of proposal (e.g., rebalance, signal_write)", max_length=50
                    ),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("draft", "DRAFT"),
                            ("generated", "GENERATED"),
                            ("submitted", "SUBMITTED"),
                            ("approved", "APPROVED"),
                            ("rejected", "REJECTED"),
                            ("executed", "EXECUTED"),
                            ("execution_failed", "EXECUTION_FAILED"),
                            ("expired", "EXPIRED"),
                        ],
                        db_index=True,
                        default="draft",
                        help_text="Proposal status",
                        max_length=20,
                    ),
                ),
                (
                    "risk_level",
                    models.CharField(
                        choices=[
                            ("low", "LOW"),
                            ("medium", "MEDIUM"),
                            ("high", "HIGH"),
                            ("critical", "CRITICAL"),
                        ],
                        default="medium",
                        help_text="Risk level assessment",
                        max_length=20,
                    ),
                ),
                (
                    "approval_required",
                    models.BooleanField(
                        default=True, help_text="Server-evaluated approval requirement"
                    ),
                ),
                (
                    "approval_status",
                    models.CharField(
                        choices=[
                            ("not_required", "NOT_REQUIRED"),
                            ("pending", "PENDING"),
                            ("approved", "APPROVED"),
                            ("rejected", "REJECTED"),
                        ],
                        default="pending",
                        help_text="Current approval status",
                        max_length=20,
                    ),
                ),
                (
                    "approval_reason",
                    models.TextField(blank=True, help_text="Human/system explanation", null=True),
                ),
                ("proposal_payload", models.JSONField(default=dict, help_text="Execution payload")),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "created_by",
                    models.ForeignKey(
                        blank=True,
                        help_text="User id",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="agent_proposals",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "task",
                    models.ForeignKey(
                        blank=True,
                        help_text="Linked task",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="proposals",
                        to="agent_runtime.agenttaskmodel",
                    ),
                ),
            ],
            options={
                "db_table": "agent_proposal",
                "ordering": ["-created_at"],
            },
        ),
        migrations.CreateModel(
            name="AgentHandoffModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "request_id",
                    models.CharField(db_index=True, help_text="Trace id", max_length=64),
                ),
                (
                    "from_agent",
                    models.CharField(help_text="Source agent identifier", max_length=100),
                ),
                ("to_agent", models.CharField(help_text="Target agent identifier", max_length=100)),
                ("handoff_reason", models.TextField(help_text="Reason for handoff")),
                (
                    "handoff_payload",
                    models.JSONField(
                        blank=True, help_text="Context payload for handoff", null=True
                    ),
                ),
                (
                    "handoff_status",
                    models.CharField(default="pending", help_text="Handoff status", max_length=20),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "task",
                    models.ForeignKey(
                        help_text="Linked task",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="handoffs",
                        to="agent_runtime.agenttaskmodel",
                    ),
                ),
            ],
            options={
                "db_table": "agent_handoff",
                "ordering": ["-created_at"],
            },
        ),
        migrations.CreateModel(
            name="AgentGuardrailDecisionModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "request_id",
                    models.CharField(db_index=True, help_text="Trace id", max_length=64),
                ),
                (
                    "decision",
                    models.CharField(
                        choices=[
                            ("allowed", "ALLOWED"),
                            ("blocked", "BLOCKED"),
                            ("needs_human", "NEEDS_HUMAN"),
                            ("degraded_mode", "DEGRADED_MODE"),
                        ],
                        default="allowed",
                        help_text="Guardrail decision",
                        max_length=20,
                    ),
                ),
                (
                    "reason_code",
                    models.CharField(help_text="Stable machine-readable reason", max_length=50),
                ),
                ("message", models.TextField(help_text="Human-readable summary")),
                ("evidence", models.JSONField(default=dict, help_text="Supporting data")),
                (
                    "requires_human",
                    models.BooleanField(default=False, help_text="Convenience flag"),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "proposal",
                    models.ForeignKey(
                        blank=True,
                        help_text="Linked proposal (optional)",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="guardrail_decisions",
                        to="agent_runtime.agentproposalmodel",
                    ),
                ),
                (
                    "task",
                    models.ForeignKey(
                        blank=True,
                        help_text="Linked task (optional)",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="guardrail_decisions",
                        to="agent_runtime.agenttaskmodel",
                    ),
                ),
            ],
            options={
                "db_table": "agent_guardrail_decision",
                "ordering": ["-created_at"],
            },
        ),
        migrations.CreateModel(
            name="AgentExecutionRecordModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "request_id",
                    models.CharField(db_index=True, help_text="Trace id", max_length=64),
                ),
                (
                    "execution_status",
                    models.CharField(
                        default="pending", help_text="Execution result status", max_length=20
                    ),
                ),
                (
                    "execution_output",
                    models.JSONField(blank=True, help_text="Execution output data", null=True),
                ),
                (
                    "started_at",
                    models.DateTimeField(blank=True, help_text="Execution start time", null=True),
                ),
                (
                    "completed_at",
                    models.DateTimeField(
                        blank=True, help_text="Execution completion time", null=True
                    ),
                ),
                (
                    "error_details",
                    models.JSONField(blank=True, help_text="Error details if failed", null=True),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "proposal",
                    models.ForeignKey(
                        blank=True,
                        help_text="Linked proposal",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="execution_records",
                        to="agent_runtime.agentproposalmodel",
                    ),
                ),
                (
                    "task",
                    models.ForeignKey(
                        help_text="Linked task",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="execution_records",
                        to="agent_runtime.agenttaskmodel",
                    ),
                ),
            ],
            options={
                "db_table": "agent_execution_record",
                "ordering": ["-created_at"],
            },
        ),
        migrations.CreateModel(
            name="AgentContextSnapshotModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "request_id",
                    models.CharField(db_index=True, help_text="Trace id", max_length=64),
                ),
                (
                    "domain",
                    models.CharField(
                        choices=[
                            ("research", "RESEARCH"),
                            ("monitoring", "MONITORING"),
                            ("decision", "DECISION"),
                            ("execution", "EXECUTION"),
                            ("ops", "OPS"),
                        ],
                        help_text="Task domain",
                        max_length=20,
                    ),
                ),
                (
                    "snapshot_data",
                    models.JSONField(default=dict, help_text="Aggregated context data"),
                ),
                (
                    "generated_at",
                    models.DateTimeField(
                        blank=True, help_text="Snapshot generation time", null=True
                    ),
                ),
                (
                    "data_freshness",
                    models.JSONField(blank=True, help_text="Data freshness metrics", null=True),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "task",
                    models.OneToOneField(
                        help_text="Linked task",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="context_snapshot",
                        to="agent_runtime.agenttaskmodel",
                    ),
                ),
            ],
            options={
                "db_table": "agent_context_snapshot",
            },
        ),
        migrations.CreateModel(
            name="AgentArtifactModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "request_id",
                    models.CharField(db_index=True, help_text="Trace id", max_length=64),
                ),
                ("artifact_type", models.CharField(help_text="Type of artifact", max_length=50)),
                ("artifact_name", models.CharField(help_text="Artifact name", max_length=200)),
                (
                    "artifact_data",
                    models.JSONField(blank=True, help_text="Artifact content", null=True),
                ),
                (
                    "file_path",
                    models.CharField(
                        blank=True,
                        help_text="Path to file if stored externally",
                        max_length=500,
                        null=True,
                    ),
                ),
                (
                    "content_type",
                    models.CharField(
                        default="application/json", help_text="MIME type", max_length=100
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "task",
                    models.ForeignKey(
                        help_text="Linked task",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="artifacts",
                        to="agent_runtime.agenttaskmodel",
                    ),
                ),
            ],
            options={
                "db_table": "agent_artifact",
                "ordering": ["-created_at"],
            },
        ),
        migrations.CreateModel(
            name="AgentTaskStepModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "request_id",
                    models.CharField(db_index=True, help_text="Trace id", max_length=64),
                ),
                ("step_key", models.CharField(help_text="Step identifier", max_length=100)),
                (
                    "step_name",
                    models.CharField(help_text="Human readable step name", max_length=200),
                ),
                ("step_index", models.IntegerField(default=0, help_text="Order index")),
                (
                    "status",
                    models.CharField(default="pending", help_text="Step status", max_length=20),
                ),
                (
                    "started_at",
                    models.DateTimeField(blank=True, help_text="Step start time", null=True),
                ),
                (
                    "completed_at",
                    models.DateTimeField(blank=True, help_text="Step completion time", null=True),
                ),
                (
                    "error_message",
                    models.TextField(blank=True, help_text="Error if failed", null=True),
                ),
                ("output_data", models.JSONField(blank=True, help_text="Step output", null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "task",
                    models.ForeignKey(
                        help_text="Linked task",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="steps",
                        to="agent_runtime.agenttaskmodel",
                    ),
                ),
            ],
            options={
                "db_table": "agent_task_step",
                "ordering": ["step_index"],
            },
        ),
        migrations.CreateModel(
            name="AgentTimelineEventModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "request_id",
                    models.CharField(db_index=True, help_text="Trace id", max_length=64),
                ),
                (
                    "event_type",
                    models.CharField(
                        choices=[
                            ("task_created", "TASK_CREATED"),
                            ("state_changed", "STATE_CHANGED"),
                            ("step_started", "STEP_STARTED"),
                            ("step_completed", "STEP_COMPLETED"),
                            ("step_failed", "STEP_FAILED"),
                            ("task_resumed", "TASK_RESUMED"),
                            ("task_cancelled", "TASK_CANCELLED"),
                            ("task_escalated", "TASK_ESCALATED"),
                        ],
                        help_text="Event type from frozen enum",
                        max_length=30,
                    ),
                ),
                (
                    "event_source",
                    models.CharField(
                        choices=[
                            ("api", "API"),
                            ("sdk", "SDK"),
                            ("mcp", "MCP"),
                            ("system", "SYSTEM"),
                            ("human", "HUMAN"),
                        ],
                        default="system",
                        help_text="Source of event (api/sdk/mcp/system/human)",
                        max_length=20,
                    ),
                ),
                (
                    "step_index",
                    models.IntegerField(blank=True, help_text="Step sequence number", null=True),
                ),
                ("event_payload", models.JSONField(default=dict, help_text="Event details")),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "proposal",
                    models.ForeignKey(
                        blank=True,
                        help_text="Linked proposal (optional)",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="timeline_events",
                        to="agent_runtime.agentproposalmodel",
                    ),
                ),
                (
                    "task",
                    models.ForeignKey(
                        help_text="Linked task",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="timeline_events",
                        to="agent_runtime.agenttaskmodel",
                    ),
                ),
            ],
            options={
                "db_table": "agent_timeline_event",
                "ordering": ["created_at"],
            },
        ),
        migrations.AddIndex(
            model_name="agenttaskmodel",
            index=models.Index(fields=["request_id"], name="agent_task_request_e3d441_idx"),
        ),
        migrations.AddIndex(
            model_name="agenttaskmodel",
            index=models.Index(fields=["status"], name="agent_task_status_01ad98_idx"),
        ),
        migrations.AddIndex(
            model_name="agenttaskmodel",
            index=models.Index(fields=["task_domain"], name="agent_task_task_do_f39261_idx"),
        ),
        migrations.AddIndex(
            model_name="agenttaskmodel",
            index=models.Index(
                fields=["task_domain", "status"], name="agent_task_task_do_7adf85_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="agenttaskmodel",
            index=models.Index(fields=["created_at"], name="agent_task_created_16aae5_idx"),
        ),
        migrations.AddIndex(
            model_name="agentproposalmodel",
            index=models.Index(fields=["request_id"], name="agent_propo_request_318bed_idx"),
        ),
        migrations.AddIndex(
            model_name="agentproposalmodel",
            index=models.Index(fields=["status"], name="agent_propo_status_a3a965_idx"),
        ),
        migrations.AddIndex(
            model_name="agentproposalmodel",
            index=models.Index(fields=["approval_status"], name="agent_propo_approva_3754bd_idx"),
        ),
        migrations.AddIndex(
            model_name="agentproposalmodel",
            index=models.Index(fields=["task"], name="agent_propo_task_id_f4f804_idx"),
        ),
        migrations.AddIndex(
            model_name="agenthandoffmodel",
            index=models.Index(fields=["request_id"], name="agent_hando_request_99738c_idx"),
        ),
        migrations.AddIndex(
            model_name="agenthandoffmodel",
            index=models.Index(fields=["task"], name="agent_hando_task_id_86b72a_idx"),
        ),
        migrations.AddIndex(
            model_name="agentguardraildecisionmodel",
            index=models.Index(fields=["request_id"], name="agent_guard_request_53490d_idx"),
        ),
        migrations.AddIndex(
            model_name="agentguardraildecisionmodel",
            index=models.Index(fields=["task"], name="agent_guard_task_id_eae900_idx"),
        ),
        migrations.AddIndex(
            model_name="agentguardraildecisionmodel",
            index=models.Index(fields=["proposal"], name="agent_guard_proposa_b2ebad_idx"),
        ),
        migrations.AddIndex(
            model_name="agentguardraildecisionmodel",
            index=models.Index(fields=["decision"], name="agent_guard_decisio_8ed072_idx"),
        ),
        migrations.AddIndex(
            model_name="agentexecutionrecordmodel",
            index=models.Index(fields=["request_id"], name="agent_execu_request_43f492_idx"),
        ),
        migrations.AddIndex(
            model_name="agentexecutionrecordmodel",
            index=models.Index(fields=["task"], name="agent_execu_task_id_2c9d76_idx"),
        ),
        migrations.AddIndex(
            model_name="agentexecutionrecordmodel",
            index=models.Index(fields=["proposal"], name="agent_execu_proposa_ad7e5d_idx"),
        ),
        migrations.AddIndex(
            model_name="agentcontextsnapshotmodel",
            index=models.Index(fields=["request_id"], name="agent_conte_request_24cdc4_idx"),
        ),
        migrations.AddIndex(
            model_name="agentcontextsnapshotmodel",
            index=models.Index(fields=["domain"], name="agent_conte_domain_e5f188_idx"),
        ),
        migrations.AddIndex(
            model_name="agentartifactmodel",
            index=models.Index(fields=["request_id"], name="agent_artif_request_060733_idx"),
        ),
        migrations.AddIndex(
            model_name="agentartifactmodel",
            index=models.Index(fields=["task"], name="agent_artif_task_id_6b58ad_idx"),
        ),
        migrations.AddIndex(
            model_name="agentartifactmodel",
            index=models.Index(fields=["artifact_type"], name="agent_artif_artifac_d0d28a_idx"),
        ),
        migrations.AddIndex(
            model_name="agenttaskstepmodel",
            index=models.Index(fields=["request_id"], name="agent_task__request_cb2114_idx"),
        ),
        migrations.AddIndex(
            model_name="agenttaskstepmodel",
            index=models.Index(
                fields=["task", "step_index"], name="agent_task__task_id_fa9c02_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="agenttimelineeventmodel",
            index=models.Index(fields=["request_id"], name="agent_timel_request_2a5592_idx"),
        ),
        migrations.AddIndex(
            model_name="agenttimelineeventmodel",
            index=models.Index(fields=["task"], name="agent_timel_task_id_30e341_idx"),
        ),
        migrations.AddIndex(
            model_name="agenttimelineeventmodel",
            index=models.Index(fields=["event_type"], name="agent_timel_event_t_14b274_idx"),
        ),
        migrations.AddIndex(
            model_name="agenttimelineeventmodel",
            index=models.Index(fields=["created_at"], name="agent_timel_created_7ef14c_idx"),
        ),
    ]
