# Generated by Django 5.2.10 on 2026-03-07 12:55

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


class Migration(migrations.Migration):

    dependencies = [
        ("rotation", "0001_initial"),
        ("simulated_trading", "0012_normalize_account_type_values"),
    ]

    operations = [
        migrations.CreateModel(
            name="RotationTemplateModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("name", models.CharField(max_length=50, unique=True, verbose_name="模板名称")),
                (
                    "key",
                    models.CharField(
                        help_text="conservative / moderate / aggressive",
                        max_length=20,
                        unique=True,
                        verbose_name="模板标识",
                    ),
                ),
                ("description", models.TextField(blank=True, verbose_name="模板描述")),
                ("regime_allocations", models.JSONField(default=dict, verbose_name="象限配置")),
                ("display_order", models.IntegerField(default=0, verbose_name="展示顺序")),
                ("is_active", models.BooleanField(default=True, verbose_name="是否启用")),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={
                "verbose_name": "轮动预设模板",
                "verbose_name_plural": "轮动预设模板",
                "db_table": "rotation_template",
                "ordering": ["display_order"],
            },
        ),
        migrations.CreateModel(
            name="PortfolioRotationConfigModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "risk_tolerance",
                    models.CharField(
                        choices=[
                            ("conservative", "保守型"),
                            ("moderate", "稳健型"),
                            ("aggressive", "激进型"),
                        ],
                        default="moderate",
                        max_length=20,
                        verbose_name="风险偏好",
                    ),
                ),
                (
                    "regime_allocations",
                    models.JSONField(blank=True, default=dict, verbose_name="象限资产配置"),
                ),
                (
                    "is_enabled",
                    models.BooleanField(
                        default=False,
                        help_text="启用后，自动交易将根据当前 Regime 使用此配置调仓",
                        verbose_name="启用轮动",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "account",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="rotation_config",
                        to="simulated_trading.simulatedaccountmodel",
                        verbose_name="投资组合账户",
                    ),
                ),
                (
                    "base_config",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="account_instances",
                        to="rotation.rotationconfigmodel",
                        verbose_name="基础模板（可选）",
                    ),
                ),
            ],
            options={
                "verbose_name": "账户轮动配置",
                "verbose_name_plural": "账户轮动配置",
                "db_table": "portfolio_rotation_config",
            },
        ),
    ]
