# Generated by Django 5.2.10 on 2026-03-05

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


class Migration(migrations.Migration):

    dependencies = [
        ("simulated_trading", "0010_rebalanceproposalmodel_notificationhistorymodel_and_more"),
        ("strategy", "0005_strategyparamversionmodel"),
    ]

    operations = [
        migrations.CreateModel(
            name="OrderIntentModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("intent_id", models.CharField(db_index=True, max_length=64, unique=True, verbose_name="意图ID")),
                (
                    "idempotency_key",
                    models.CharField(db_index=True, max_length=128, unique=True, verbose_name="幂等键"),
                ),
                ("symbol", models.CharField(db_index=True, max_length=32, verbose_name="资产代码")),
                (
                    "side",
                    models.CharField(
                        choices=[("buy", "买入"), ("sell", "卖出")], max_length=8, verbose_name="方向"
                    ),
                ),
                ("qty", models.PositiveIntegerField(verbose_name="数量")),
                ("limit_price", models.FloatField(blank=True, null=True, verbose_name="限价")),
                (
                    "time_in_force",
                    models.CharField(
                        choices=[("day", "DAY"), ("gtc", "GTC"), ("ioc", "IOC"), ("fok", "FOK")],
                        default="day",
                        max_length=8,
                        verbose_name="订单时效",
                    ),
                ),
                ("reason", models.TextField(blank=True, verbose_name="原因")),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("draft", "草稿"),
                            ("pending_approval", "待审批"),
                            ("approved", "已批准"),
                            ("rejected", "已拒绝"),
                            ("sent", "已发送"),
                            ("partial_filled", "部分成交"),
                            ("filled", "已成交"),
                            ("canceled", "已取消"),
                            ("failed", "失败"),
                        ],
                        db_index=True,
                        default="draft",
                        max_length=32,
                        verbose_name="状态",
                    ),
                ),
                ("decision_json", models.JSONField(default=dict, verbose_name="决策快照")),
                ("sizing_json", models.JSONField(default=dict, verbose_name="仓位快照")),
                ("risk_snapshot_json", models.JSONField(default=dict, verbose_name="风控快照")),
                ("created_at", models.DateTimeField(db_index=True, default=django.utils.timezone.now, verbose_name="创建时间")),
                ("updated_at", models.DateTimeField(auto_now=True, verbose_name="更新时间")),
                (
                    "portfolio",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="strategy_order_intents",
                        to="simulated_trading.simulatedaccountmodel",
                        verbose_name="投资组合",
                    ),
                ),
                (
                    "strategy",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="order_intents",
                        to="strategy.strategymodel",
                        verbose_name="策略",
                    ),
                ),
            ],
            options={
                "verbose_name": "订单意图",
                "verbose_name_plural": "订单意图",
                "db_table": "order_intent",
                "ordering": ["-created_at"],
            },
        ),
        migrations.AddIndex(
            model_name="orderintentmodel",
            index=models.Index(fields=["portfolio", "status"], name="order_inten_portfol_aeab65_idx"),
        ),
        migrations.AddIndex(
            model_name="orderintentmodel",
            index=models.Index(fields=["strategy", "-created_at"], name="order_inten_strateg_2ae2f2_idx"),
        ),
        migrations.AddIndex(
            model_name="orderintentmodel",
            index=models.Index(fields=["symbol", "-created_at"], name="order_inten_symbol_0872b3_idx"),
        ),
    ]
