# Generated by Django 5.2.10 on 2026-03-12 06:53

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="ShareLinkModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "account_id",
                    models.IntegerField(
                        db_index=True, help_text="关联的模拟账户ID", verbose_name="关联账户ID"
                    ),
                ),
                (
                    "short_code",
                    models.CharField(
                        db_index=True,
                        help_text="用于公开访问的唯一短码",
                        max_length=16,
                        unique=True,
                        verbose_name="短码",
                    ),
                ),
                ("title", models.CharField(max_length=100, verbose_name="标题")),
                (
                    "subtitle",
                    models.CharField(blank=True, max_length=200, null=True, verbose_name="副标题"),
                ),
                (
                    "share_level",
                    models.CharField(
                        choices=[
                            ("snapshot", "静态快照"),
                            ("observer", "观察者模式"),
                            ("research", "研究模式"),
                        ],
                        db_index=True,
                        default="snapshot",
                        help_text="决定数据展示的详细程度",
                        max_length=20,
                        verbose_name="分享级别",
                    ),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("active", "活跃"),
                            ("revoked", "已撤销"),
                            ("expired", "已过期"),
                            ("disabled", "已禁用"),
                        ],
                        db_index=True,
                        default="active",
                        max_length=20,
                        verbose_name="状态",
                    ),
                ),
                (
                    "password_hash",
                    models.CharField(
                        blank=True,
                        help_text="使用 Django 的 make_password 生成",
                        max_length=128,
                        null=True,
                        verbose_name="密码哈希",
                    ),
                ),
                (
                    "expires_at",
                    models.DateTimeField(
                        blank=True,
                        db_index=True,
                        help_text="过期后无法访问",
                        null=True,
                        verbose_name="过期时间",
                    ),
                ),
                (
                    "max_access_count",
                    models.IntegerField(
                        blank=True,
                        help_text="null 表示无限制",
                        null=True,
                        verbose_name="最大访问次数",
                    ),
                ),
                ("access_count", models.IntegerField(default=0, verbose_name="访问次数")),
                (
                    "last_snapshot_at",
                    models.DateTimeField(
                        blank=True,
                        help_text="最近一次生成快照的时间",
                        null=True,
                        verbose_name="最后快照时间",
                    ),
                ),
                (
                    "last_accessed_at",
                    models.DateTimeField(blank=True, null=True, verbose_name="最后访问时间"),
                ),
                (
                    "allow_indexing",
                    models.BooleanField(
                        default=False,
                        help_text="允许后页面可被搜索引擎收录",
                        verbose_name="允许搜索引擎索引",
                    ),
                ),
                ("show_amounts", models.BooleanField(default=False, verbose_name="显示金额")),
                ("show_positions", models.BooleanField(default=True, verbose_name="显示持仓")),
                ("show_transactions", models.BooleanField(default=True, verbose_name="显示交易")),
                (
                    "show_decision_summary",
                    models.BooleanField(default=True, verbose_name="显示决策摘要"),
                ),
                (
                    "show_decision_evidence",
                    models.BooleanField(default=False, verbose_name="显示决策依据"),
                ),
                (
                    "show_invalidation_logic",
                    models.BooleanField(default=False, verbose_name="显示证伪逻辑"),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True, verbose_name="创建时间")),
                ("updated_at", models.DateTimeField(auto_now=True, verbose_name="更新时间")),
                (
                    "owner",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="share_links",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="所有者",
                    ),
                ),
            ],
            options={
                "verbose_name": "分享链接",
                "verbose_name_plural": "分享链接",
                "db_table": "share_link",
                "ordering": ["-created_at"],
            },
        ),
        migrations.CreateModel(
            name="ShareAccessLogModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "accessed_at",
                    models.DateTimeField(auto_now_add=True, db_index=True, verbose_name="访问时间"),
                ),
                (
                    "ip_hash",
                    models.CharField(
                        db_index=True,
                        help_text="IP地址的哈希值，不存储原始IP",
                        max_length=64,
                        verbose_name="IP哈希",
                    ),
                ),
                (
                    "user_agent",
                    models.TextField(
                        blank=True,
                        help_text="浏览器/客户端信息",
                        null=True,
                        verbose_name="用户代理",
                    ),
                ),
                (
                    "referer",
                    models.TextField(
                        blank=True, help_text="HTTP Referer", null=True, verbose_name="来源页面"
                    ),
                ),
                (
                    "is_verified",
                    models.BooleanField(
                        default=False,
                        help_text="是否通过密码验证（如果有密码）",
                        verbose_name="已验证",
                    ),
                ),
                (
                    "result_status",
                    models.CharField(
                        choices=[
                            ("success", "成功"),
                            ("password_required", "需要密码"),
                            ("password_invalid", "密码错误"),
                            ("expired", "已过期"),
                            ("revoked", "已撤销"),
                            ("max_count_exceeded", "超过访问次数"),
                            ("not_found", "不存在"),
                        ],
                        db_index=True,
                        default="success",
                        max_length=30,
                        verbose_name="访问结果",
                    ),
                ),
                (
                    "share_link",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="access_logs",
                        to="share.sharelinkmodel",
                        verbose_name="分享链接",
                    ),
                ),
            ],
            options={
                "verbose_name": "访问日志",
                "verbose_name_plural": "访问日志",
                "db_table": "share_access_log",
                "ordering": ["-accessed_at"],
            },
        ),
        migrations.CreateModel(
            name="ShareSnapshotModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "snapshot_version",
                    models.IntegerField(
                        default=1, help_text="同一分享链接的快照版本号", verbose_name="快照版本"
                    ),
                ),
                (
                    "summary_payload",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text="账户摘要信息",
                        null=True,
                        verbose_name="摘要数据",
                    ),
                ),
                (
                    "performance_payload",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text="绩效指标",
                        null=True,
                        verbose_name="绩效数据",
                    ),
                ),
                (
                    "positions_payload",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text="持仓列表",
                        null=True,
                        verbose_name="持仓数据",
                    ),
                ),
                (
                    "transactions_payload",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text="交易记录",
                        null=True,
                        verbose_name="交易数据",
                    ),
                ),
                (
                    "decision_payload",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text="决策依据和证伪逻辑",
                        null=True,
                        verbose_name="决策数据",
                    ),
                ),
                (
                    "generated_at",
                    models.DateTimeField(auto_now_add=True, db_index=True, verbose_name="生成时间"),
                ),
                (
                    "source_range_start",
                    models.DateField(
                        blank=True,
                        help_text="快照数据的起始日期",
                        null=True,
                        verbose_name="数据起始日期",
                    ),
                ),
                (
                    "source_range_end",
                    models.DateField(
                        blank=True,
                        help_text="快照数据的结束日期",
                        null=True,
                        verbose_name="数据结束日期",
                    ),
                ),
                (
                    "share_link",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="snapshots",
                        to="share.sharelinkmodel",
                        verbose_name="分享链接",
                    ),
                ),
            ],
            options={
                "verbose_name": "分享快照",
                "verbose_name_plural": "分享快照",
                "db_table": "share_snapshot",
                "ordering": ["-snapshot_version"],
            },
        ),
        migrations.AddIndex(
            model_name="sharelinkmodel",
            index=models.Index(
                fields=["owner", "-created_at"], name="share_link_owner_i_d28411_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="sharelinkmodel",
            index=models.Index(fields=["short_code"], name="share_link_short_c_028c85_idx"),
        ),
        migrations.AddIndex(
            model_name="sharelinkmodel",
            index=models.Index(
                fields=["status", "-created_at"], name="share_link_status_af71fe_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="sharelinkmodel",
            index=models.Index(fields=["expires_at"], name="share_link_expires_c7acc4_idx"),
        ),
        migrations.AddIndex(
            model_name="sharelinkmodel",
            index=models.Index(fields=["account_id"], name="share_link_account_5595a3_idx"),
        ),
        migrations.AddIndex(
            model_name="shareaccesslogmodel",
            index=models.Index(
                fields=["share_link", "-accessed_at"], name="share_acces_share_l_e8bd06_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="shareaccesslogmodel",
            index=models.Index(fields=["ip_hash"], name="share_acces_ip_hash_04a20e_idx"),
        ),
        migrations.AddIndex(
            model_name="shareaccesslogmodel",
            index=models.Index(fields=["result_status"], name="share_acces_result__780c2b_idx"),
        ),
        migrations.AddIndex(
            model_name="shareaccesslogmodel",
            index=models.Index(fields=["-accessed_at"], name="share_acces_accesse_a675ba_idx"),
        ),
        migrations.AddIndex(
            model_name="sharesnapshotmodel",
            index=models.Index(
                fields=["share_link", "-snapshot_version"], name="share_snaps_share_l_8cfc2d_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="sharesnapshotmodel",
            index=models.Index(fields=["-generated_at"], name="share_snaps_generat_417467_idx"),
        ),
        migrations.AlterUniqueTogether(
            name="sharesnapshotmodel",
            unique_together={("share_link", "snapshot_version")},
        ),
    ]
