# Generated by Django 5.2.9 on 2025-12-29 22:49

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


class Migration(migrations.Migration):

    initial = True

    dependencies = []

    operations = [
        migrations.CreateModel(
            name="ChatSessionORM",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "session_id",
                    models.CharField(
                        db_index=True, help_text="会话ID", max_length=100, unique=True
                    ),
                ),
                ("user_message", models.TextField(help_text="用户消息")),
                ("ai_response", models.TextField(help_text="AI响应")),
                ("context", models.JSONField(blank=True, default=dict, help_text="上下文数据")),
                (
                    "created_at",
                    models.DateTimeField(auto_now_add=True, db_index=True, help_text="创建时间"),
                ),
            ],
            options={
                "verbose_name": "聊天会话",
                "verbose_name_plural": "聊天会话",
                "db_table": "chat_session",
                "ordering": ["-created_at"],
            },
        ),
        migrations.CreateModel(
            name="ChainConfigORM",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        db_index=True, help_text="链名称（唯一标识）", max_length=100, unique=True
                    ),
                ),
                (
                    "category",
                    models.CharField(
                        choices=[
                            ("report", "Report Analysis"),
                            ("signal", "Signal Generation"),
                            ("analysis", "Data Analysis"),
                            ("chat", "Chat"),
                        ],
                        db_index=True,
                        help_text="分类",
                        max_length=20,
                    ),
                ),
                ("description", models.TextField(blank=True, help_text="描述")),
                ("steps", models.JSONField(default=list, help_text="步骤定义列表")),
                (
                    "execution_mode",
                    models.CharField(
                        choices=[
                            ("serial", "Serial"),
                            ("parallel", "Parallel"),
                            ("tool", "Tool Calling"),
                            ("hybrid", "Hybrid"),
                        ],
                        default="serial",
                        help_text="执行模式",
                        max_length=20,
                    ),
                ),
                (
                    "aggregate_step",
                    models.JSONField(blank=True, help_text="汇总步骤配置", null=True),
                ),
                (
                    "is_active",
                    models.BooleanField(db_index=True, default=True, help_text="是否激活"),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True, help_text="创建时间")),
                ("updated_at", models.DateTimeField(auto_now=True, help_text="更新时间")),
            ],
            options={
                "verbose_name": "链配置",
                "verbose_name_plural": "链配置",
                "db_table": "chain_config",
                "ordering": ["category", "name"],
                "indexes": [
                    models.Index(
                        fields=["category", "is_active"], name="chain_confi_categor_1b067e_idx"
                    )
                ],
            },
        ),
        migrations.CreateModel(
            name="PromptTemplateORM",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        db_index=True, help_text="模板名称（唯一标识）", max_length=100, unique=True
                    ),
                ),
                (
                    "category",
                    models.CharField(
                        choices=[
                            ("report", "Report Analysis"),
                            ("signal", "Signal Generation"),
                            ("analysis", "Data Analysis"),
                            ("chat", "Chat"),
                        ],
                        db_index=True,
                        help_text="分类",
                        max_length=20,
                    ),
                ),
                ("version", models.CharField(default="1.0", help_text="版本号", max_length=20)),
                ("template_content", models.TextField(help_text="模板内容（支持Jinja2语法）")),
                ("system_prompt", models.TextField(blank=True, help_text="系统提示词")),
                (
                    "placeholders",
                    models.JSONField(blank=True, default=list, help_text="占位符定义列表"),
                ),
                ("temperature", models.FloatField(default=0.7, help_text="温度参数（0.0-2.0）")),
                ("max_tokens", models.IntegerField(blank=True, help_text="最大token数", null=True)),
                ("description", models.TextField(blank=True, help_text="描述")),
                (
                    "is_active",
                    models.BooleanField(db_index=True, default=True, help_text="是否激活"),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True, help_text="创建时间")),
                ("updated_at", models.DateTimeField(auto_now=True, help_text="更新时间")),
                (
                    "last_used_at",
                    models.DateTimeField(blank=True, help_text="最后使用时间", null=True),
                ),
            ],
            options={
                "verbose_name": "Prompt模板",
                "verbose_name_plural": "Prompt模板",
                "db_table": "prompt_template",
                "ordering": ["category", "name"],
                "indexes": [
                    models.Index(
                        fields=["category", "is_active"], name="prompt_temp_categor_f42610_idx"
                    )
                ],
            },
        ),
        migrations.CreateModel(
            name="PromptExecutionLogORM",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "execution_id",
                    models.CharField(db_index=True, help_text="执行ID", max_length=100),
                ),
                (
                    "step_id",
                    models.CharField(blank=True, help_text="步骤ID", max_length=50, null=True),
                ),
                (
                    "placeholder_values",
                    models.JSONField(blank=True, default=dict, help_text="占位符值"),
                ),
                ("rendered_prompt", models.TextField(help_text="渲染后的Prompt")),
                ("ai_response", models.TextField(help_text="AI响应内容")),
                (
                    "parsed_output",
                    models.JSONField(blank=True, help_text="解析后的输出", null=True),
                ),
                ("response_time_ms", models.IntegerField(help_text="响应时间（毫秒）")),
                ("prompt_tokens", models.IntegerField(default=0, help_text="输入token数")),
                ("completion_tokens", models.IntegerField(default=0, help_text="输出token数")),
                ("total_tokens", models.IntegerField(default=0, help_text="总token数")),
                (
                    "estimated_cost",
                    models.DecimalField(
                        decimal_places=6, default=0, help_text="预估成本", max_digits=10
                    ),
                ),
                (
                    "provider_used",
                    models.CharField(blank=True, help_text="使用的提供商", max_length=50),
                ),
                ("model_used", models.CharField(blank=True, help_text="使用的模型", max_length=50)),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("success", "Success"),
                            ("error", "Error"),
                            ("timeout", "Timeout"),
                        ],
                        default="success",
                        help_text="执行状态",
                        max_length=20,
                    ),
                ),
                ("error_message", models.TextField(blank=True, help_text="错误信息")),
                (
                    "created_at",
                    models.DateTimeField(auto_now_add=True, db_index=True, help_text="执行时间"),
                ),
                (
                    "chain",
                    models.ForeignKey(
                        blank=True,
                        help_text="关联的链",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="execution_logs",
                        to="prompt.chainconfigorm",
                    ),
                ),
                (
                    "template",
                    models.ForeignKey(
                        blank=True,
                        help_text="关联的模板",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="execution_logs",
                        to="prompt.prompttemplateorm",
                    ),
                ),
            ],
            options={
                "verbose_name": "执行日志",
                "verbose_name_plural": "执行日志",
                "db_table": "prompt_execution_log",
                "ordering": ["-created_at"],
                "indexes": [
                    models.Index(
                        fields=["execution_id", "-created_at"],
                        name="prompt_exec_executi_cb0ad4_idx",
                    ),
                    models.Index(
                        fields=["template", "-created_at"], name="prompt_exec_templat_ba3a9b_idx"
                    ),
                    models.Index(
                        fields=["status", "-created_at"], name="prompt_exec_status_043bc8_idx"
                    ),
                ],
            },
        ),
    ]
