# Generated by Django 5.2.9 on 2025-12-31 06:28

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


class Migration(migrations.Migration):

    dependencies = [
        ("account", "0002_portfoliodailysnapshotmodel_and_more"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="InvestmentRuleModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("name", models.CharField(max_length=100, verbose_name="规则名称")),
                (
                    "rule_type",
                    models.CharField(
                        choices=[
                            ("regime_advice", "Regime环境建议"),
                            ("position_advice", "仓位建议"),
                            ("match_advice", "Regime匹配度建议"),
                            ("signal_advice", "投资信号建议"),
                            ("risk_alert", "风险提示"),
                        ],
                        max_length=20,
                        verbose_name="规则类型",
                    ),
                ),
                (
                    "priority",
                    models.IntegerField(default=100, verbose_name="优先级（数字越小越优先）"),
                ),
                ("is_active", models.BooleanField(default=True, verbose_name="是否启用")),
                ("conditions", models.JSONField(default=dict, verbose_name="触发条件")),
                ("advice_template", models.TextField(verbose_name="建议模板")),
                ("created_at", models.DateTimeField(auto_now_add=True, verbose_name="创建时间")),
                ("updated_at", models.DateTimeField(auto_now=True, verbose_name="更新时间")),
                (
                    "user",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="investment_rules",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="用户（null表示全局默认规则）",
                    ),
                ),
            ],
            options={
                "verbose_name": "投资规则",
                "verbose_name_plural": "投资规则",
                "db_table": "investment_rule",
                "ordering": ["priority", "id"],
                "indexes": [
                    models.Index(
                        fields=["user", "rule_type", "is_active"],
                        name="investment__user_id_f6f69b_idx",
                    )
                ],
            },
        ),
    ]
