# Generated by Django 5.2.12 on 2026-04-16 03:59

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="DashboardAlertModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "alert_id",
                    models.CharField(
                        db_index=True, help_text="告警唯一标识符", max_length=64, unique=True
                    ),
                ),
                ("name", models.CharField(help_text="告警名称", max_length=100)),
                ("description", models.TextField(blank=True, help_text="描述")),
                ("metric", models.CharField(blank=True, help_text="监控指标", max_length=100)),
                ("condition", models.CharField(blank=True, help_text="告警条件", max_length=50)),
                (
                    "severity",
                    models.CharField(
                        choices=[
                            ("info", "INFO"),
                            ("warning", "WARNING"),
                            ("error", "ERROR"),
                            ("critical", "CRITICAL"),
                        ],
                        default="warning",
                        help_text="告警级别",
                        max_length=20,
                    ),
                ),
                ("threshold", models.FloatField(blank=True, help_text="阈值", null=True)),
                (
                    "notification_channels",
                    models.JSONField(blank=True, default=list, help_text="通知渠道"),
                ),
                ("is_enabled", models.BooleanField(default=True, help_text="是否启用")),
                ("cooldown", models.IntegerField(default=300, help_text="冷却时间（秒）")),
                (
                    "last_triggered_at",
                    models.DateTimeField(blank=True, help_text="最后触发时间", null=True),
                ),
                ("trigger_count", models.IntegerField(default=0, help_text="触发次数")),
                ("created_at", models.DateTimeField(auto_now_add=True, help_text="创建时间")),
                ("updated_at", models.DateTimeField(auto_now=True, help_text="更新时间")),
            ],
            options={
                "verbose_name": "仪表盘告警",
                "verbose_name_plural": "仪表盘告警",
                "db_table": "dashboard_alert",
                "ordering": ["severity", "name"],
            },
        ),
        migrations.CreateModel(
            name="DashboardCardModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "card_id",
                    models.CharField(
                        db_index=True, help_text="卡片唯一标识符", max_length=64, unique=True
                    ),
                ),
                (
                    "card_type",
                    models.CharField(
                        choices=[
                            ("metric", "METRIC"),
                            ("chart", "CHART"),
                            ("list", "LIST"),
                            ("alert", "ALERT"),
                            ("table", "TABLE"),
                            ("custom", "CUSTOM"),
                        ],
                        help_text="卡片类型",
                        max_length=20,
                    ),
                ),
                ("title", models.CharField(blank=True, help_text="卡片标题", max_length=100)),
                ("description", models.TextField(blank=True, help_text="描述")),
                ("widget_config", models.JSONField(blank=True, default=dict, help_text="组件配置")),
                ("data_source", models.CharField(blank=True, help_text="数据源", max_length=200)),
                (
                    "visibility_conditions",
                    models.JSONField(blank=True, default=dict, help_text="可见性条件"),
                ),
                ("position", models.JSONField(blank=True, default=dict, help_text="位置配置")),
                ("size", models.JSONField(blank=True, default=dict, help_text="尺寸配置")),
                ("is_visible", models.BooleanField(default=True, help_text="是否可见")),
                ("is_collapsible", models.BooleanField(default=True, help_text="是否可折叠")),
                ("is_draggable", models.BooleanField(default=True, help_text="是否可拖动")),
                ("is_resizable", models.BooleanField(default=True, help_text="是否可调整大小")),
                (
                    "dependencies",
                    models.JSONField(blank=True, default=list, help_text="依赖的卡片ID列表"),
                ),
                ("display_order", models.IntegerField(default=0, help_text="显示顺序")),
                ("created_at", models.DateTimeField(auto_now_add=True, help_text="创建时间")),
                ("updated_at", models.DateTimeField(auto_now=True, help_text="更新时间")),
            ],
            options={
                "verbose_name": "仪表盘卡片",
                "verbose_name_plural": "仪表盘卡片",
                "db_table": "dashboard_card",
                "ordering": ["display_order", "card_id"],
            },
        ),
        migrations.CreateModel(
            name="DashboardConfigModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "config_id",
                    models.CharField(
                        db_index=True, help_text="配置唯一标识符", max_length=64, unique=True
                    ),
                ),
                ("name", models.CharField(help_text="配置名称", max_length=100)),
                ("description", models.TextField(blank=True, help_text="描述")),
                ("layout_config", models.JSONField(blank=True, default=dict, help_text="布局配置")),
                (
                    "card_configs",
                    models.JSONField(blank=True, default=list, help_text="卡片配置列表"),
                ),
                ("is_default", models.BooleanField(default=False, help_text="是否默认配置")),
                ("is_active", models.BooleanField(default=True, help_text="是否激活")),
                ("created_at", models.DateTimeField(auto_now_add=True, help_text="创建时间")),
                ("updated_at", models.DateTimeField(auto_now=True, help_text="更新时间")),
            ],
            options={
                "verbose_name": "仪表盘配置",
                "verbose_name_plural": "仪表盘配置",
                "db_table": "dashboard_config",
                "ordering": ["-is_default", "name"],
            },
        ),
        migrations.CreateModel(
            name="AlphaRecommendationRunModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("portfolio_id", models.IntegerField(blank=True, db_index=True, null=True)),
                ("portfolio_name", models.CharField(blank=True, max_length=120)),
                ("trade_date", models.DateField(db_index=True)),
                ("scope_hash", models.CharField(db_index=True, max_length=32)),
                ("scope_label", models.CharField(blank=True, max_length=200)),
                ("scope_metadata", models.JSONField(blank=True, default=dict)),
                ("model_hash", models.CharField(blank=True, max_length=128)),
                ("source", models.CharField(db_index=True, max_length=32)),
                ("provider_source", models.CharField(blank=True, max_length=32)),
                ("requested_trade_date", models.DateField(blank=True, null=True)),
                ("effective_asof_date", models.DateField(blank=True, null=True)),
                ("uses_cached_data", models.BooleanField(default=False)),
                ("cache_reason", models.TextField(blank=True)),
                ("fallback_reason", models.TextField(blank=True)),
                ("meta", models.JSONField(blank=True, default=dict)),
                ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="alpha_recommendation_runs",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "db_table": "dashboard_alpha_recommendation_run",
                "ordering": ["-trade_date", "-created_at"],
            },
        ),
        migrations.CreateModel(
            name="AlphaRecommendationSnapshotModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("stock_code", models.CharField(db_index=True, max_length=16)),
                ("stock_name", models.CharField(blank=True, max_length=120)),
                ("stage", models.CharField(db_index=True, max_length=32)),
                ("gate_status", models.CharField(db_index=True, max_length=16)),
                ("rank", models.IntegerField(default=0)),
                ("alpha_score", models.FloatField(default=0.0)),
                ("confidence", models.FloatField(default=0.0)),
                ("source", models.CharField(blank=True, max_length=32)),
                ("buy_reasons", models.JSONField(blank=True, default=list)),
                ("no_buy_reasons", models.JSONField(blank=True, default=list)),
                ("invalidation_rule", models.JSONField(blank=True, default=dict)),
                ("risk_snapshot", models.JSONField(blank=True, default=dict)),
                ("suggested_position_pct", models.FloatField(default=0.0)),
                ("suggested_notional", models.FloatField(default=0.0)),
                ("suggested_quantity", models.FloatField(default=0.0)),
                ("source_candidate_id", models.IntegerField(blank=True, null=True)),
                ("source_recommendation_id", models.IntegerField(blank=True, null=True)),
                ("extra_payload", models.JSONField(blank=True, default=dict)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "run",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="snapshots",
                        to="dashboard.alpharecommendationrunmodel",
                    ),
                ),
            ],
            options={
                "db_table": "dashboard_alpha_recommendation_snapshot",
                "ordering": ["rank", "stock_code"],
            },
        ),
        migrations.CreateModel(
            name="DashboardSnapshotModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("snapshot_data", models.JSONField(help_text="快照数据")),
                (
                    "captured_at",
                    models.DateTimeField(auto_now_add=True, db_index=True, help_text="捕获时间"),
                ),
                (
                    "user",
                    models.ForeignKey(
                        help_text="关联用户",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="dashboard_snapshots",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "仪表盘快照",
                "verbose_name_plural": "仪表盘快照",
                "db_table": "dashboard_snapshot",
                "ordering": ["-captured_at"],
            },
        ),
        migrations.CreateModel(
            name="DashboardUserConfigModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "hidden_cards",
                    models.JSONField(blank=True, default=list, help_text="隐藏的卡片ID列表"),
                ),
                (
                    "collapsed_cards",
                    models.JSONField(blank=True, default=list, help_text="折叠的卡片ID列表"),
                ),
                ("card_order", models.JSONField(blank=True, default=list, help_text="卡片顺序")),
                (
                    "custom_card_config",
                    models.JSONField(blank=True, default=dict, help_text="自定义卡片配置"),
                ),
                ("theme", models.CharField(default="light", help_text="主题", max_length=20)),
                (
                    "refresh_enabled",
                    models.BooleanField(default=True, help_text="是否启用自动刷新"),
                ),
                ("refresh_interval", models.IntegerField(default=60, help_text="刷新间隔（秒）")),
                ("last_updated", models.DateTimeField(auto_now=True, help_text="最后更新时间")),
                (
                    "dashboard_config",
                    models.ForeignKey(
                        blank=True,
                        help_text="仪表盘配置",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="user_configs",
                        to="dashboard.dashboardconfigmodel",
                    ),
                ),
                (
                    "user",
                    models.OneToOneField(
                        help_text="关联用户",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="dashboard_config",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "verbose_name": "用户仪表盘配置",
                "verbose_name_plural": "用户仪表盘配置",
                "db_table": "dashboard_user_config",
            },
        ),
        migrations.AddIndex(
            model_name="alpharecommendationrunmodel",
            index=models.Index(
                fields=["user", "portfolio_id", "trade_date"], name="dashboard_a_user_id_4eecaf_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="alpharecommendationrunmodel",
            index=models.Index(
                fields=["scope_hash", "trade_date"], name="dashboard_a_scope_h_98cd6b_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="alpharecommendationrunmodel",
            index=models.Index(
                fields=["source", "trade_date"], name="dashboard_a_source_6c06f0_idx"
            ),
        ),
        migrations.AlterUniqueTogether(
            name="alpharecommendationrunmodel",
            unique_together={
                ("user", "portfolio_id", "trade_date", "scope_hash", "model_hash", "source")
            },
        ),
        migrations.AddIndex(
            model_name="alpharecommendationsnapshotmodel",
            index=models.Index(fields=["run", "stage"], name="dashboard_a_run_id_908ad4_idx"),
        ),
        migrations.AddIndex(
            model_name="alpharecommendationsnapshotmodel",
            index=models.Index(
                fields=["stock_code", "stage"], name="dashboard_a_stock_c_26677e_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="alpharecommendationsnapshotmodel",
            index=models.Index(fields=["gate_status"], name="dashboard_a_gate_st_d05d1f_idx"),
        ),
        migrations.AlterUniqueTogether(
            name="alpharecommendationsnapshotmodel",
            unique_together={("run", "stock_code")},
        ),
        migrations.AlterUniqueTogether(
            name="dashboarduserconfigmodel",
            unique_together={("user", "dashboard_config")},
        ),
    ]
