# Generated manually

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


class Migration(migrations.Migration):

    dependencies = [
        ('contenttypes', '0002_remove_content_type_name'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('stateflow', '0010_remove_orderstatelog_notes_and_more'),
    ]

    operations = [
        # 先重命名表（保留数据）
        migrations.RenameModel(
            old_name='Order',
            new_name='BusinessObject',
        ),
        migrations.RenameModel(
            old_name='OrderStateLog',
            new_name='StateFlowRecord',
        ),
        
        # 更新 BusinessObject 的字段
        migrations.AlterModelOptions(
            name='businessobject',
            options={'verbose_name': '业务对象', 'verbose_name_plural': '业务对象'},
        ),
        migrations.AlterModelTable(
            name='businessobject',
            table='business_object',
        ),
        
        # 添加 GenericForeignKey 字段
        migrations.AddField(
            model_name='businessobject',
            name='content_type',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype', verbose_name='关联对象类型', default=1),
            preserve_default=False,
        ),
        migrations.AddField(
            model_name='businessobject',
            name='object_id',
            field=models.PositiveIntegerField(verbose_name='关联对象ID', default=0),
            preserve_default=False,
        ),
        
        # 更新 StateFlowRecord
        migrations.RenameField(
            model_name='stateflowrecord',
            old_name='order',
            new_name='business_object',
        ),
        migrations.AlterModelOptions(
            name='stateflowrecord',
            options={'ordering': ['completed_at'], 'verbose_name': '状态流转记录', 'verbose_name_plural': '状态流转记录'},
        ),
        migrations.AlterModelTable(
            name='stateflowrecord',
            table='state_flow_record',
        ),
        migrations.AlterUniqueTogether(
            name='stateflowrecord',
            unique_together={('business_object', 'state')},
        ),
        
        # 更新 Process 的 related_name
        migrations.AlterField(
            model_name='businessobject',
            name='process',
            field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='business_objects', to='stateflow.process', verbose_name='关联流程'),
        ),
    ]
