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

import django.db.models.deletion
import simple_history.models
import uuid
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='HistoricalImportBatch',
            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')),
                ('title', models.CharField(blank=True, max_length=180, verbose_name='Designação')),
                ('source_file', models.TextField(max_length=100, verbose_name='Ficheiro Excel')),
                ('original_filename', models.CharField(blank=True, max_length=255, verbose_name='Nome original')),
                ('status', models.CharField(choices=[('uploaded', 'Carregado'), ('analysing', 'Em análise'), ('review', 'Em revisão'), ('ready', 'Pronto para importar'), ('imported', 'Importado'), ('failed', 'Falhou'), ('cancelled', 'Cancelado')], db_index=True, default='uploaded', max_length=20, verbose_name='Estado')),
                ('selected_sheets', models.JSONField(blank=True, default=list, verbose_name='Folhas selecionadas')),
                ('total_rows', models.PositiveIntegerField(default=0, verbose_name='Linhas analisadas')),
                ('valid_rows', models.PositiveIntegerField(default=0, verbose_name='Linhas válidas')),
                ('warning_rows', models.PositiveIntegerField(default=0, verbose_name='Com avisos')),
                ('error_rows', models.PositiveIntegerField(default=0, verbose_name='Com erros')),
                ('ignored_rows', models.PositiveIntegerField(default=0, verbose_name='Ignoradas')),
                ('analysed_at', models.DateTimeField(blank=True, null=True, verbose_name='Analisado em')),
                ('notes', models.TextField(blank=True, verbose_name='Notas')),
                ('error_message', models.TextField(blank=True, verbose_name='Erro da análise')),
                ('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)),
                ('created_by', 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='Criado por')),
                ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'historical Importação Excel',
                'verbose_name_plural': 'historical Importações Excel',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='ImportBatch',
            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')),
                ('title', models.CharField(blank=True, max_length=180, verbose_name='Designação')),
                ('source_file', models.FileField(upload_to='imports/%Y/%m/', verbose_name='Ficheiro Excel')),
                ('original_filename', models.CharField(blank=True, max_length=255, verbose_name='Nome original')),
                ('status', models.CharField(choices=[('uploaded', 'Carregado'), ('analysing', 'Em análise'), ('review', 'Em revisão'), ('ready', 'Pronto para importar'), ('imported', 'Importado'), ('failed', 'Falhou'), ('cancelled', 'Cancelado')], db_index=True, default='uploaded', max_length=20, verbose_name='Estado')),
                ('selected_sheets', models.JSONField(blank=True, default=list, verbose_name='Folhas selecionadas')),
                ('total_rows', models.PositiveIntegerField(default=0, verbose_name='Linhas analisadas')),
                ('valid_rows', models.PositiveIntegerField(default=0, verbose_name='Linhas válidas')),
                ('warning_rows', models.PositiveIntegerField(default=0, verbose_name='Com avisos')),
                ('error_rows', models.PositiveIntegerField(default=0, verbose_name='Com erros')),
                ('ignored_rows', models.PositiveIntegerField(default=0, verbose_name='Ignoradas')),
                ('analysed_at', models.DateTimeField(blank=True, null=True, verbose_name='Analisado em')),
                ('notes', models.TextField(blank=True, verbose_name='Notas')),
                ('error_message', models.TextField(blank=True, verbose_name='Erro da análise')),
                ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='import_batches', to=settings.AUTH_USER_MODEL, verbose_name='Criado por')),
            ],
            options={
                'verbose_name': 'Importação Excel',
                'verbose_name_plural': 'Importações Excel',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='HistoricalImportRow',
            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')),
                ('sheet_name', models.CharField(db_index=True, max_length=100, verbose_name='Folha')),
                ('row_number', models.PositiveIntegerField(verbose_name='Linha')),
                ('record_type', models.CharField(choices=[('hosting', 'Alojamento'), ('domain', 'Domínio'), ('website', 'Projeto web'), ('technical', 'Dado técnico'), ('payment', 'Pagamento histórico'), ('unknown', 'Por classificar')], db_index=True, default='unknown', max_length=20, verbose_name='Tipo detetado')),
                ('source_label', models.CharField(blank=True, max_length=300, verbose_name='Identificação original')),
                ('raw_data', models.JSONField(blank=True, default=dict, verbose_name='Dados originais')),
                ('normalized_data', models.JSONField(blank=True, default=dict, verbose_name='Dados normalizados')),
                ('severity', models.CharField(choices=[('valid', 'Válida'), ('warning', 'Com aviso'), ('error', 'Com erro')], db_index=True, default='warning', max_length=15, verbose_name='Validação')),
                ('decision', models.CharField(choices=[('pending', 'Por decidir'), ('import', 'Importar'), ('ignore', 'Ignorar'), ('archive', 'Arquivar como histórico'), ('link', 'Associar a registo existente')], db_index=True, default='pending', max_length=15, verbose_name='Decisão')),
                ('issues', models.JSONField(blank=True, default=list, verbose_name='Problemas encontrados')),
                ('proposed_client_name', models.CharField(blank=True, max_length=180, verbose_name='Cliente proposto')),
                ('proposed_service_name', models.CharField(blank=True, max_length=180, verbose_name='Serviço proposto')),
                ('proposed_domain_name', models.CharField(blank=True, max_length=253, verbose_name='Domínio proposto')),
                ('proposed_service_type', models.CharField(blank=True, choices=[('domain', 'Domínio'), ('hosting', 'Alojamento web'), ('email', 'Email profissional'), ('ssl', 'Certificado SSL'), ('maintenance', 'Manutenção'), ('website', 'Website / projeto'), ('backup', 'Backup'), ('server', 'Servidor'), ('other', 'Outro')], max_length=20, verbose_name='Tipo de serviço proposto')),
                ('proposed_renewal_date', models.DateField(blank=True, null=True, verbose_name='Data de renovação proposta')),
                ('proposed_cost_price', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True, verbose_name='Custo proposto')),
                ('proposed_sale_price', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True, verbose_name='Valor a cobrar proposto')),
                ('proposed_status', models.CharField(blank=True, max_length=100, verbose_name='Estado original / proposto')),
                ('proposed_notes', models.TextField(blank=True, verbose_name='Notas de revisão')),
                ('duplicate_key', models.CharField(blank=True, db_index=True, max_length=300, verbose_name='Chave de duplicação')),
                ('target_model', models.CharField(blank=True, max_length=100, verbose_name='Modelo de destino')),
                ('target_object_id', models.CharField(blank=True, max_length=100, verbose_name='Registo existente')),
                ('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)),
                ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('batch', 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')),
            ],
            options={
                'verbose_name': 'historical Linha de importação',
                'verbose_name_plural': 'historical Linhas de importação',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='ImportRow',
            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')),
                ('sheet_name', models.CharField(db_index=True, max_length=100, verbose_name='Folha')),
                ('row_number', models.PositiveIntegerField(verbose_name='Linha')),
                ('record_type', models.CharField(choices=[('hosting', 'Alojamento'), ('domain', 'Domínio'), ('website', 'Projeto web'), ('technical', 'Dado técnico'), ('payment', 'Pagamento histórico'), ('unknown', 'Por classificar')], db_index=True, default='unknown', max_length=20, verbose_name='Tipo detetado')),
                ('source_label', models.CharField(blank=True, max_length=300, verbose_name='Identificação original')),
                ('raw_data', models.JSONField(blank=True, default=dict, verbose_name='Dados originais')),
                ('normalized_data', models.JSONField(blank=True, default=dict, verbose_name='Dados normalizados')),
                ('severity', models.CharField(choices=[('valid', 'Válida'), ('warning', 'Com aviso'), ('error', 'Com erro')], db_index=True, default='warning', max_length=15, verbose_name='Validação')),
                ('decision', models.CharField(choices=[('pending', 'Por decidir'), ('import', 'Importar'), ('ignore', 'Ignorar'), ('archive', 'Arquivar como histórico'), ('link', 'Associar a registo existente')], db_index=True, default='pending', max_length=15, verbose_name='Decisão')),
                ('issues', models.JSONField(blank=True, default=list, verbose_name='Problemas encontrados')),
                ('proposed_client_name', models.CharField(blank=True, max_length=180, verbose_name='Cliente proposto')),
                ('proposed_service_name', models.CharField(blank=True, max_length=180, verbose_name='Serviço proposto')),
                ('proposed_domain_name', models.CharField(blank=True, max_length=253, verbose_name='Domínio proposto')),
                ('proposed_service_type', models.CharField(blank=True, choices=[('domain', 'Domínio'), ('hosting', 'Alojamento web'), ('email', 'Email profissional'), ('ssl', 'Certificado SSL'), ('maintenance', 'Manutenção'), ('website', 'Website / projeto'), ('backup', 'Backup'), ('server', 'Servidor'), ('other', 'Outro')], max_length=20, verbose_name='Tipo de serviço proposto')),
                ('proposed_renewal_date', models.DateField(blank=True, null=True, verbose_name='Data de renovação proposta')),
                ('proposed_cost_price', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True, verbose_name='Custo proposto')),
                ('proposed_sale_price', models.DecimalField(blank=True, decimal_places=2, max_digits=12, null=True, verbose_name='Valor a cobrar proposto')),
                ('proposed_status', models.CharField(blank=True, max_length=100, verbose_name='Estado original / proposto')),
                ('proposed_notes', models.TextField(blank=True, verbose_name='Notas de revisão')),
                ('duplicate_key', models.CharField(blank=True, db_index=True, max_length=300, verbose_name='Chave de duplicação')),
                ('target_model', models.CharField(blank=True, max_length=100, verbose_name='Modelo de destino')),
                ('target_object_id', models.CharField(blank=True, max_length=100, verbose_name='Registo existente')),
                ('batch', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='rows', to='imports.importbatch', verbose_name='Importação')),
            ],
            options={
                'verbose_name': 'Linha de importação',
                'verbose_name_plural': 'Linhas de importação',
                'ordering': ['batch', 'sheet_name', 'row_number'],
                'indexes': [models.Index(fields=['batch', 'severity', 'decision'], name='imports_imp_batch_i_cb8f83_idx'), models.Index(fields=['record_type', 'duplicate_key'], name='imports_imp_record__985acd_idx')],
                'constraints': [models.UniqueConstraint(fields=('batch', 'sheet_name', 'row_number'), name='unique_import_sheet_row')],
            },
        ),
    ]
