# Generated by Django 5.2.10 on 2026-03-19 10:27

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


class Migration(migrations.Migration):

    dependencies = [
        ("terminal", "0001_initial"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.AddField(
            model_name="terminalcommandorm",
            name="enabled_in_terminal",
            field=models.BooleanField(db_index=True, default=True, help_text="是否在终端中显示"),
        ),
        migrations.AddField(
            model_name="terminalcommandorm",
            name="requires_mcp",
            field=models.BooleanField(default=True, help_text="是否需要 MCP 权限"),
        ),
        migrations.AddField(
            model_name="terminalcommandorm",
            name="risk_level",
            field=models.CharField(
                choices=[
                    ("read", "只读"),
                    ("write_low", "低风险写入"),
                    ("write_high", "高风险写入"),
                    ("admin", "管理员"),
                ],
                db_index=True,
                default="read",
                help_text="风险等级",
                max_length=20,
            ),
        ),
        migrations.CreateModel(
            name="TerminalAuditLogORM",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("username", models.CharField(db_index=True, max_length=150)),
                ("session_id", models.CharField(db_index=True, max_length=100)),
                ("command_name", models.CharField(db_index=True, max_length=50)),
                ("risk_level", models.CharField(max_length=20)),
                ("mode", models.CharField(max_length=20)),
                ("params_summary", models.TextField(blank=True)),
                ("confirmation_required", models.BooleanField(default=False)),
                (
                    "confirmation_status",
                    models.CharField(
                        choices=[
                            ("confirmed", "已确认"),
                            ("cancelled", "已取消"),
                            ("not_required", "无需确认"),
                            ("expired", "已过期"),
                        ],
                        default="not_required",
                        max_length=20,
                    ),
                ),
                (
                    "result_status",
                    models.CharField(
                        choices=[
                            ("success", "成功"),
                            ("error", "错误"),
                            ("blocked", "被阻止"),
                            ("pending", "等待确认"),
                        ],
                        default="pending",
                        max_length=20,
                    ),
                ),
                ("error_message", models.TextField(blank=True)),
                ("duration_ms", models.IntegerField(default=0)),
                ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
                (
                    "user",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "终端审计日志",
                "verbose_name_plural": "终端审计日志",
                "db_table": "terminal_audit_log",
                "ordering": ["-created_at"],
            },
        ),
    ]
