# Generated by Django 5.2 on 2025-12-31

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='AssetMetadataModel',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('asset_code', models.CharField(db_index=True, max_length=50, unique=True, verbose_name='资产代码')),
                ('name', models.CharField(max_length=200, verbose_name='资产名称')),
                ('description', models.TextField(blank=True, verbose_name='描述')),
                ('asset_class', models.CharField(choices=[('equity', '股票'), ('fixed_income', '固定收益'), ('commodity', '商品'), ('currency', '外汇'), ('cash', '现金'), ('fund', '基金'), ('derivative', '衍生品'), ('other', '其他')], max_length=20, verbose_name='资产大类')),
                ('region', models.CharField(choices=[('CN', '中国境内'), ('US', '美国'), ('EU', '欧洲'), ('JP', '日本'), ('EM', '新兴市场'), ('GLOBAL', '全球'), ('OTHER', '其他')], max_length=10, verbose_name='地区')),
                ('cross_border', models.CharField(choices=[('domestic', '境内资产'), ('qdii', 'QDII基金'), ('direct_foreign', '直接境外投资')], default='domestic', max_length=20, verbose_name='跨境标识')),
                ('style', models.CharField(choices=[('growth', '成长'), ('value', '价值'), ('blend', '混合'), ('cyclical', '周期'), ('defensive', '防御'), ('quality', '质量'), ('momentum', '动量'), ('unknown', '未知/不适用')], default='unknown', max_length=20, verbose_name='投资风格')),
                ('sector', models.CharField(blank=True, max_length=50, verbose_name='行业板块')),
                ('sub_class', models.CharField(blank=True, max_length=50, verbose_name='子类')),
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
            ],
            options={
                'verbose_name': '资产元数据',
                'verbose_name_plural': '资产元数据',
                'db_table': 'asset_metadata',
                'indexes': [
                    models.Index(fields=['asset_code'], name='account_a_asset__code_idx'),
                    models.Index(fields=['asset_class', 'region'], name='account_a_asset__class_idx'),
                ],
            },
        ),
        migrations.CreateModel(
            name='AccountProfileModel',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('display_name', models.CharField(max_length=100, verbose_name='显示名称')),
                ('initial_capital', models.DecimalField(decimal_places=2, default=1000000.00, max_digits=20, verbose_name='初始资金')),
                ('risk_tolerance', models.CharField(choices=[('conservative', '保守型'), ('moderate', '稳健型'), ('aggressive', '激进型')], default='moderate', max_length=20, verbose_name='风险偏好')),
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='account_profile', to=settings.AUTH_USER_MODEL, verbose_name='用户')),
            ],
            options={
                'verbose_name': '账户配置',
                'verbose_name_plural': '账户配置',
                'db_table': 'account_profile',
            },
        ),
        migrations.CreateModel(
            name='PortfolioModel',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(default='默认组合', max_length=100, verbose_name='组合名称')),
                ('is_active', models.BooleanField(default=True, verbose_name='是否激活')),
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='portfolios', to=settings.AUTH_USER_MODEL, verbose_name='用户')),
            ],
            options={
                'verbose_name': '投资组合',
                'verbose_name_plural': '投资组合',
                'db_table': 'portfolio',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='PositionModel',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('asset_code', models.CharField(db_index=True, max_length=20, verbose_name='资产代码')),
                ('asset_class', models.CharField(choices=[('equity', '股票'), ('fixed_income', '固定收益'), ('commodity', '商品'), ('currency', '外汇'), ('cash', '现金'), ('fund', '基金'), ('derivative', '衍生品'), ('other', '其他')], max_length=20, verbose_name='资产大类')),
                ('region', models.CharField(choices=[('CN', '中国境内'), ('US', '美国'), ('EU', '欧洲'), ('JP', '日本'), ('EM', '新兴市场'), ('GLOBAL', '全球'), ('OTHER', '其他')], max_length=10, verbose_name='地区')),
                ('cross_border', models.CharField(choices=[('domestic', '境内资产'), ('qdii', 'QDII基金'), ('direct_foreign', '直接境外投资')], max_length=20, verbose_name='跨境标识')),
                ('shares', models.FloatField(verbose_name='持仓数量')),
                ('avg_cost', models.DecimalField(decimal_places=4, max_digits=20, verbose_name='平均成本价')),
                ('current_price', models.DecimalField(decimal_places=4, max_digits=20, null=True, verbose_name='当前市价')),
                ('market_value', models.DecimalField(decimal_places=2, default=0, max_digits=20, verbose_name='市值')),
                ('unrealized_pnl', models.DecimalField(decimal_places=2, default=0, max_digits=20, verbose_name='未实现盈亏')),
                ('unrealized_pnl_pct', models.FloatField(default=0, verbose_name='未实现盈亏百分比')),
                ('source', models.CharField(choices=[('manual', '手动录入'), ('signal', '投资信号'), ('backtest', '回测结果')], default='manual', max_length=20, verbose_name='来源')),
                ('source_id', models.IntegerField(blank=True, null=True, verbose_name='来源ID')),
                ('is_closed', models.BooleanField(default=False, verbose_name='是否已平仓')),
                ('opened_at', models.DateTimeField(auto_now_add=True, verbose_name='开仓时间')),
                ('closed_at', models.DateTimeField(blank=True, null=True, verbose_name='平仓时间')),
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
                ('portfolio', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='positions', to='account.portfolioModel', verbose_name='投资组合')),
            ],
            options={
                'verbose_name': '持仓记录',
                'verbose_name_plural': '持仓记录',
                'db_table': 'position',
                'indexes': [
                    models.Index(fields=['portfolio', 'asset_code'], name='account_p_portfoli__asset__code_idx'),
                    models.Index(fields=['source', 'source_id'], name='account_p_source__source__id_idx'),
                    models.Index(fields=['asset_class', 'region'], name='account_p_asset__class__region_idx'),
                    models.Index(fields=['is_closed'], name='account_p_is_closed_idx'),
                ],
            },
        ),
        migrations.CreateModel(
            name='TransactionModel',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('action', models.CharField(choices=[('buy', '买入'), ('sell', '卖出')], max_length=10, verbose_name='交易方向')),
                ('asset_code', models.CharField(max_length=20, verbose_name='资产代码')),
                ('shares', models.FloatField(verbose_name='交易数量')),
                ('price', models.DecimalField(decimal_places=4, max_digits=20, verbose_name='成交价格')),
                ('notional', models.DecimalField(decimal_places=2, max_digits=20, verbose_name='成交金额')),
                ('commission', models.DecimalField(decimal_places=2, default=0, max_digits=10, verbose_name='手续费')),
                ('traded_at', models.DateTimeField(verbose_name='交易时间')),
                ('notes', models.TextField(blank=True, verbose_name='备注')),
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
                ('portfolio', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='transactions', to='account.portfolioModel', verbose_name='投资组合')),
                ('position', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='transactions', to='account.positionmodel', verbose_name='关联持仓')),
            ],
            options={
                'verbose_name': '交易记录',
                'verbose_name_plural': '交易记录',
                'db_table': 'transaction',
                'ordering': ['-traded_at'],
                'indexes': [
                    models.Index(fields=['portfolio', 'traded_at'], name='account_t_portfolio__traded__at_idx'),
                    models.Index(fields=['asset_code'], name='account_t_asset_code_idx'),
                ],
            },
        ),
        migrations.CreateModel(
            name='PositionSignalLogModel',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('signal_id', models.IntegerField(verbose_name='信号ID')),
                ('executed_at', models.DateTimeField(auto_now_add=True, verbose_name='执行时间')),
                ('notes', models.TextField(blank=True, verbose_name='备注')),
                ('position', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='signal_logs', to='account.positionmodel', verbose_name='持仓')),
            ],
            options={
                'verbose_name': '持仓信号日志',
                'verbose_name_plural': '持仓信号日志',
                'db_table': 'position_signal_log',
            },
        ),
    ]
