# Generated by Django 5.2.12 on 2026-05-31 08:00

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("decision_rhythm", "0012_add_fallback_valuation_method"),
    ]

    operations = [
        migrations.CreateModel(
            name="DecisionExecutionLinkModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "recommendation_id",
                    models.CharField(
                        blank=True,
                        db_index=True,
                        default="",
                        help_text="关联的统一推荐 ID；manual_only 时为空",
                        max_length=64,
                    ),
                ),
                (
                    "transaction_id",
                    models.IntegerField(db_index=True, help_text="account.TransactionModel ID"),
                ),
                ("account_id", models.CharField(db_index=True, help_text="账户 ID", max_length=64)),
                (
                    "security_code",
                    models.CharField(db_index=True, help_text="证券代码", max_length=32),
                ),
                ("actual_action", models.CharField(help_text="实际动作 buy/sell", max_length=16)),
                (
                    "match_method",
                    models.CharField(
                        choices=[
                            ("auto", "自动匹配"),
                            ("manual", "人工关联"),
                            ("manual_only", "仅人工操作"),
                        ],
                        db_index=True,
                        default="auto",
                        help_text="匹配方式",
                        max_length=32,
                    ),
                ),
                ("match_confidence", models.FloatField(default=0.0, help_text="匹配置信度")),
                ("notes", models.TextField(blank=True, default="", help_text="备注")),
                ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
            ],
            options={
                "verbose_name": "推荐执行关联",
                "verbose_name_plural": "推荐执行关联",
                "db_table": "decision_execution_link",
                "ordering": ["-created_at"],
                "indexes": [
                    models.Index(
                        fields=["account_id", "security_code"], name="idx_exec_link_acc_sec"
                    ),
                    models.Index(
                        fields=["match_method", "-created_at"], name="idx_exec_link_method_time"
                    ),
                ],
                "constraints": [
                    models.UniqueConstraint(
                        fields=("transaction_id", "recommendation_id"),
                        name="uq_decision_exec_link_tx_recommendation",
                    )
                ],
            },
        ),
    ]
