# Generated by Django 5.2.15 on 2026-06-15 10:18

import django.db.models.deletion
import imports.models
import simple_history.models
import uuid
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('contenttypes', '0002_remove_content_type_name'),
        ('imports', '0001_initial'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='HistoricalImportedObject',
            fields=[
                ('id', models.BigIntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
                ('public_id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False)),
                ('created_at', models.DateTimeField(blank=True, editable=False, verbose_name='Criado em')),
                ('updated_at', models.DateTimeField(blank=True, editable=False, verbose_name='Atualizado em')),
                ('object_id', models.PositiveBigIntegerField(verbose_name='ID do registo')),
                ('action', models.CharField(choices=[('created', 'Criado'), ('linked', 'Associado'), ('reused', 'Reutilizado')], db_index=True, default='created', max_length=15, verbose_name='Ação')),
                ('label', models.CharField(blank=True, max_length=300, verbose_name='Identificação')),
                ('object_updated_at', models.DateTimeField(blank=True, null=True, verbose_name='Atualização no momento da importação')),
                ('rollback_blocked_reason', models.TextField(blank=True, verbose_name='Motivo de bloqueio da anulação')),
                ('history_id', models.AutoField(primary_key=True, serialize=False)),
                ('history_date', models.DateTimeField(db_index=True)),
                ('history_change_reason', models.CharField(max_length=100, null=True)),
                ('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
            ],
            options={
                'verbose_name': 'historical Registo importado',
                'verbose_name_plural': 'historical Registos importados',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='ImportedObject',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('public_id', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Criado em')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Atualizado em')),
                ('object_id', models.PositiveBigIntegerField(verbose_name='ID do registo')),
                ('action', models.CharField(choices=[('created', 'Criado'), ('linked', 'Associado'), ('reused', 'Reutilizado')], db_index=True, default='created', max_length=15, verbose_name='Ação')),
                ('label', models.CharField(blank=True, max_length=300, verbose_name='Identificação')),
                ('object_updated_at', models.DateTimeField(blank=True, null=True, verbose_name='Atualização no momento da importação')),
                ('rollback_blocked_reason', models.TextField(blank=True, verbose_name='Motivo de bloqueio da anulação')),
            ],
            options={
                'verbose_name': 'Registo importado',
                'verbose_name_plural': 'Registos importados',
                'ordering': ['batch', 'created_at'],
            },
        ),
        migrations.AddField(
            model_name='historicalimportbatch',
            name='code',
            field=models.CharField(blank=True, db_index=True, default=imports.models.generate_import_code, max_length=24, verbose_name='Código'),
        ),
        migrations.AddField(
            model_name='historicalimportbatch',
            name='executed_by',
            field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL, verbose_name='Executado por'),
        ),
        migrations.AddField(
            model_name='historicalimportbatch',
            name='import_summary',
            field=models.JSONField(blank=True, default=dict, verbose_name='Resumo da importação'),
        ),
        migrations.AddField(
            model_name='historicalimportbatch',
            name='imported_at',
            field=models.DateTimeField(blank=True, null=True, verbose_name='Importado em'),
        ),
        migrations.AddField(
            model_name='historicalimportbatch',
            name='rollback_summary',
            field=models.JSONField(blank=True, default=dict, verbose_name='Resumo da anulação'),
        ),
        migrations.AddField(
            model_name='historicalimportbatch',
            name='rolled_back_at',
            field=models.DateTimeField(blank=True, null=True, verbose_name='Anulado em'),
        ),
        migrations.AddField(
            model_name='historicalimportbatch',
            name='simulated_at',
            field=models.DateTimeField(blank=True, null=True, verbose_name='Simulado em'),
        ),
        migrations.AddField(
            model_name='historicalimportbatch',
            name='simulation_summary',
            field=models.JSONField(blank=True, default=dict, verbose_name='Resumo da simulação'),
        ),
        migrations.AddField(
            model_name='historicalimportrow',
            name='processed_at',
            field=models.DateTimeField(blank=True, null=True, verbose_name='Processada em'),
        ),
        migrations.AddField(
            model_name='historicalimportrow',
            name='processing_message',
            field=models.TextField(blank=True, verbose_name='Resultado do processamento'),
        ),
        migrations.AddField(
            model_name='historicalimportrow',
            name='processing_status',
            field=models.CharField(choices=[('pending', 'Não processada'), ('simulated', 'Simulada'), ('created', 'Criada'), ('linked', 'Associada'), ('skipped', 'Ignorada'), ('failed', 'Falhou'), ('rolled_back', 'Anulada')], db_index=True, default='pending', max_length=20, verbose_name='Processamento'),
        ),
        migrations.AddField(
            model_name='importbatch',
            name='code',
            field=models.CharField(blank=True, db_index=True, default=imports.models.generate_import_code, max_length=24, verbose_name='Código'),
        ),
        migrations.AddField(
            model_name='importbatch',
            name='executed_by',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='executed_import_batches', to=settings.AUTH_USER_MODEL, verbose_name='Executado por'),
        ),
        migrations.AddField(
            model_name='importbatch',
            name='import_summary',
            field=models.JSONField(blank=True, default=dict, verbose_name='Resumo da importação'),
        ),
        migrations.AddField(
            model_name='importbatch',
            name='imported_at',
            field=models.DateTimeField(blank=True, null=True, verbose_name='Importado em'),
        ),
        migrations.AddField(
            model_name='importbatch',
            name='rollback_summary',
            field=models.JSONField(blank=True, default=dict, verbose_name='Resumo da anulação'),
        ),
        migrations.AddField(
            model_name='importbatch',
            name='rolled_back_at',
            field=models.DateTimeField(blank=True, null=True, verbose_name='Anulado em'),
        ),
        migrations.AddField(
            model_name='importbatch',
            name='simulated_at',
            field=models.DateTimeField(blank=True, null=True, verbose_name='Simulado em'),
        ),
        migrations.AddField(
            model_name='importbatch',
            name='simulation_summary',
            field=models.JSONField(blank=True, default=dict, verbose_name='Resumo da simulação'),
        ),
        migrations.AddField(
            model_name='importrow',
            name='processed_at',
            field=models.DateTimeField(blank=True, null=True, verbose_name='Processada em'),
        ),
        migrations.AddField(
            model_name='importrow',
            name='processing_message',
            field=models.TextField(blank=True, verbose_name='Resultado do processamento'),
        ),
        migrations.AddField(
            model_name='importrow',
            name='processing_status',
            field=models.CharField(choices=[('pending', 'Não processada'), ('simulated', 'Simulada'), ('created', 'Criada'), ('linked', 'Associada'), ('skipped', 'Ignorada'), ('failed', 'Falhou'), ('rolled_back', 'Anulada')], db_index=True, default='pending', max_length=20, verbose_name='Processamento'),
        ),
        migrations.AlterField(
            model_name='historicalimportbatch',
            name='error_message',
            field=models.TextField(blank=True, verbose_name='Erro da análise/importação'),
        ),
        migrations.AlterField(
            model_name='historicalimportbatch',
            name='status',
            field=models.CharField(choices=[('uploaded', 'Carregado'), ('analysing', 'Em análise'), ('review', 'Em revisão'), ('ready', 'Pronto para simular'), ('simulated', 'Simulado'), ('importing', 'A importar'), ('imported', 'Importado'), ('rolled_back', 'Anulado'), ('failed', 'Falhou'), ('cancelled', 'Cancelado')], db_index=True, default='uploaded', max_length=20, verbose_name='Estado'),
        ),
        migrations.AlterField(
            model_name='importbatch',
            name='error_message',
            field=models.TextField(blank=True, verbose_name='Erro da análise/importação'),
        ),
        migrations.AlterField(
            model_name='importbatch',
            name='status',
            field=models.CharField(choices=[('uploaded', 'Carregado'), ('analysing', 'Em análise'), ('review', 'Em revisão'), ('ready', 'Pronto para simular'), ('simulated', 'Simulado'), ('importing', 'A importar'), ('imported', 'Importado'), ('rolled_back', 'Anulado'), ('failed', 'Falhou'), ('cancelled', 'Cancelado')], db_index=True, default='uploaded', max_length=20, verbose_name='Estado'),
        ),
        migrations.AddIndex(
            model_name='importrow',
            index=models.Index(fields=['batch', 'processing_status'], name='imports_imp_batch_i_1a723a_idx'),
        ),
        migrations.AddField(
            model_name='historicalimportedobject',
            name='batch',
            field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='imports.importbatch', verbose_name='Importação'),
        ),
        migrations.AddField(
            model_name='historicalimportedobject',
            name='content_type',
            field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='contenttypes.contenttype', verbose_name='Tipo de registo'),
        ),
        migrations.AddField(
            model_name='historicalimportedobject',
            name='history_user',
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AddField(
            model_name='historicalimportedobject',
            name='row',
            field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='imports.importrow', verbose_name='Linha'),
        ),
        migrations.AddField(
            model_name='importedobject',
            name='batch',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='imported_objects', to='imports.importbatch', verbose_name='Importação'),
        ),
        migrations.AddField(
            model_name='importedobject',
            name='content_type',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype', verbose_name='Tipo de registo'),
        ),
        migrations.AddField(
            model_name='importedobject',
            name='row',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='imported_objects', to='imports.importrow', verbose_name='Linha'),
        ),
        migrations.AddIndex(
            model_name='importedobject',
            index=models.Index(fields=['batch', 'action'], name='imports_imp_batch_i_33c826_idx'),
        ),
        migrations.AddIndex(
            model_name='importedobject',
            index=models.Index(fields=['content_type', 'object_id'], name='imports_imp_content_1eacb4_idx'),
        ),
        migrations.AddConstraint(
            model_name='importedobject',
            constraint=models.UniqueConstraint(fields=('batch', 'content_type', 'object_id', 'action'), name='unique_imported_object_action'),
        ),
    ]
