# Generated by Django 5.2.9 on 2026-02-08 17:12

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


class Migration(migrations.Migration):

    dependencies = [
        ("strategy", "0004_positionmanagementrulemodel"),
        ("simulated_trading", "0006_rename_simulated_posi_account_id_idx_simulated_p_account_db88fb_idx_and_more"),
    ]

    operations = [
        migrations.CreateModel(
            name="DailyInspectionReportModel",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("inspection_date", models.DateField(db_index=True, verbose_name="巡检日期")),
                (
                    "status",
                    models.CharField(
                        choices=[("ok", "正常"), ("warning", "预警"), ("error", "异常")],
                        db_index=True,
                        default="ok",
                        max_length=20,
                        verbose_name="巡检状态",
                    ),
                ),
                ("macro_regime", models.CharField(blank=True, default="", max_length=32, verbose_name="宏观象限")),
                ("policy_gear", models.CharField(blank=True, default="", max_length=8, verbose_name="政策档位")),
                ("total_value", models.DecimalField(decimal_places=2, default=0, max_digits=15, verbose_name="账户总资产")),
                ("current_cash", models.DecimalField(decimal_places=2, default=0, max_digits=15, verbose_name="账户现金")),
                ("current_market_value", models.DecimalField(decimal_places=2, default=0, max_digits=15, verbose_name="持仓市值")),
                ("checks", models.JSONField(blank=True, default=list, verbose_name="巡检明细")),
                ("summary", models.JSONField(blank=True, default=dict, verbose_name="巡检汇总")),
                ("created_at", models.DateTimeField(auto_now_add=True, verbose_name="创建时间")),
                ("updated_at", models.DateTimeField(auto_now=True, verbose_name="更新时间")),
                (
                    "account",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="inspection_reports",
                        to="simulated_trading.simulatedaccountmodel",
                        verbose_name="所属账户",
                    ),
                ),
                (
                    "position_rule",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="inspection_reports",
                        to="strategy.positionmanagementrulemodel",
                        verbose_name="仓位规则",
                    ),
                ),
                (
                    "strategy",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="inspection_reports",
                        to="strategy.strategymodel",
                        verbose_name="关联策略",
                    ),
                ),
            ],
            options={
                "verbose_name": "模拟盘日更巡检报告",
                "verbose_name_plural": "模拟盘日更巡检报告",
                "db_table": "simulated_daily_inspection_report",
                "ordering": ["-inspection_date", "-updated_at"],
            },
        ),
        migrations.AddIndex(
            model_name="dailyinspectionreportmodel",
            index=models.Index(fields=["account", "-inspection_date"], name="simulated_d_account_a973a7_idx"),
        ),
        migrations.AddIndex(
            model_name="dailyinspectionreportmodel",
            index=models.Index(fields=["inspection_date", "status"], name="simulated_d_inspect_3ad5f2_idx"),
        ),
        migrations.AlterUniqueTogether(
            name="dailyinspectionreportmodel",
            unique_together={("account", "inspection_date")},
        ),
    ]
