# Generated by Django 5.2.15 on 2026-06-15 08:28

import django.db.models.deletion
import django.utils.timezone
import simple_history.models
import uuid
from decimal import Decimal
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('services', '0001_initial'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='HistoricalRenewal',
            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')),
                ('due_date', models.DateField(db_index=True, verbose_name='Data de vencimento')),
                ('period_start', models.DateField(blank=True, null=True, verbose_name='Início do período')),
                ('period_end', models.DateField(blank=True, null=True, verbose_name='Fim do período')),
                ('cost_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=10, verbose_name='Custo')),
                ('sale_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=10, verbose_name='Valor a cobrar')),
                ('status', models.CharField(choices=[('to_notify', 'Por avisar'), ('notified', 'Avisado'), ('waiting_payment', 'A aguardar pagamento'), ('partial', 'Pagamento parcial'), ('paid', 'Pago'), ('renewed', 'Renovado'), ('overdue', 'Vencido'), ('cancelled', 'Cancelado')], db_index=True, default='to_notify', max_length=25, verbose_name='Estado')),
                ('notice_30_sent_at', models.DateTimeField(blank=True, null=True, verbose_name='Aviso 30 dias')),
                ('notice_15_sent_at', models.DateTimeField(blank=True, null=True, verbose_name='Aviso 15 dias')),
                ('notice_7_sent_at', models.DateTimeField(blank=True, null=True, verbose_name='Aviso 7 dias')),
                ('due_notice_sent_at', models.DateTimeField(blank=True, null=True, verbose_name='Aviso no vencimento')),
                ('overdue_notice_sent_at', models.DateTimeField(blank=True, null=True, verbose_name='Aviso de vencido')),
                ('paid_at', models.DateTimeField(blank=True, null=True, verbose_name='Pago em')),
                ('renewed_until', models.DateField(blank=True, null=True, verbose_name='Renovado até')),
                ('notes', models.TextField(blank=True, verbose_name='Observações')),
                ('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)),
                ('service', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='services.service', verbose_name='Serviço')),
            ],
            options={
                'verbose_name': 'historical Renovação',
                'verbose_name_plural': 'historical Renovações',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='Renewal',
            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')),
                ('due_date', models.DateField(db_index=True, verbose_name='Data de vencimento')),
                ('period_start', models.DateField(blank=True, null=True, verbose_name='Início do período')),
                ('period_end', models.DateField(blank=True, null=True, verbose_name='Fim do período')),
                ('cost_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=10, verbose_name='Custo')),
                ('sale_amount', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=10, verbose_name='Valor a cobrar')),
                ('status', models.CharField(choices=[('to_notify', 'Por avisar'), ('notified', 'Avisado'), ('waiting_payment', 'A aguardar pagamento'), ('partial', 'Pagamento parcial'), ('paid', 'Pago'), ('renewed', 'Renovado'), ('overdue', 'Vencido'), ('cancelled', 'Cancelado')], db_index=True, default='to_notify', max_length=25, verbose_name='Estado')),
                ('notice_30_sent_at', models.DateTimeField(blank=True, null=True, verbose_name='Aviso 30 dias')),
                ('notice_15_sent_at', models.DateTimeField(blank=True, null=True, verbose_name='Aviso 15 dias')),
                ('notice_7_sent_at', models.DateTimeField(blank=True, null=True, verbose_name='Aviso 7 dias')),
                ('due_notice_sent_at', models.DateTimeField(blank=True, null=True, verbose_name='Aviso no vencimento')),
                ('overdue_notice_sent_at', models.DateTimeField(blank=True, null=True, verbose_name='Aviso de vencido')),
                ('paid_at', models.DateTimeField(blank=True, null=True, verbose_name='Pago em')),
                ('renewed_until', models.DateField(blank=True, null=True, verbose_name='Renovado até')),
                ('notes', models.TextField(blank=True, verbose_name='Observações')),
                ('service', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='renewals', to='services.service', verbose_name='Serviço')),
            ],
            options={
                'verbose_name': 'Renovação',
                'verbose_name_plural': 'Renovações',
                'ordering': ['due_date', 'service__client__name'],
            },
        ),
        migrations.CreateModel(
            name='Payment',
            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')),
                ('amount', models.DecimalField(decimal_places=2, max_digits=10, verbose_name='Valor')),
                ('method', models.CharField(choices=[('mbway', 'MB WAY'), ('bank_transfer', 'Transferência bancária'), ('cash', 'Dinheiro'), ('card', 'Cartão'), ('complimentary', 'Oferta'), ('client_direct', 'Pago diretamente pelo cliente'), ('other', 'Outro')], max_length=30, verbose_name='Método')),
                ('status', models.CharField(choices=[('pending', 'Pendente'), ('waiting_proof', 'A aguardar comprovativo'), ('validating', 'Em validação'), ('partial', 'Parcial'), ('paid', 'Pago'), ('rejected', 'Rejeitado'), ('cancelled', 'Cancelado'), ('refunded', 'Devolvido')], db_index=True, default='pending', max_length=25, verbose_name='Estado')),
                ('requested_at', models.DateTimeField(default=django.utils.timezone.now, verbose_name='Solicitado em')),
                ('paid_at', models.DateTimeField(blank=True, null=True, verbose_name='Pago em')),
                ('proof', models.FileField(blank=True, upload_to='payment_proofs/%Y/%m/', verbose_name='Comprovativo')),
                ('reference', models.CharField(blank=True, max_length=120, verbose_name='Referência interna')),
                ('invoice_number', models.CharField(blank=True, max_length=120, verbose_name='Fatura / recibo')),
                ('notes', models.TextField(blank=True, verbose_name='Observações')),
                ('renewal', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='payments', to='billing.renewal', verbose_name='Renovação')),
            ],
            options={
                'verbose_name': 'Pagamento',
                'verbose_name_plural': 'Pagamentos',
                'ordering': ['-requested_at'],
            },
        ),
        migrations.CreateModel(
            name='HistoricalPayment',
            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')),
                ('amount', models.DecimalField(decimal_places=2, max_digits=10, verbose_name='Valor')),
                ('method', models.CharField(choices=[('mbway', 'MB WAY'), ('bank_transfer', 'Transferência bancária'), ('cash', 'Dinheiro'), ('card', 'Cartão'), ('complimentary', 'Oferta'), ('client_direct', 'Pago diretamente pelo cliente'), ('other', 'Outro')], max_length=30, verbose_name='Método')),
                ('status', models.CharField(choices=[('pending', 'Pendente'), ('waiting_proof', 'A aguardar comprovativo'), ('validating', 'Em validação'), ('partial', 'Parcial'), ('paid', 'Pago'), ('rejected', 'Rejeitado'), ('cancelled', 'Cancelado'), ('refunded', 'Devolvido')], db_index=True, default='pending', max_length=25, verbose_name='Estado')),
                ('requested_at', models.DateTimeField(default=django.utils.timezone.now, verbose_name='Solicitado em')),
                ('paid_at', models.DateTimeField(blank=True, null=True, verbose_name='Pago em')),
                ('proof', models.TextField(blank=True, max_length=100, verbose_name='Comprovativo')),
                ('reference', models.CharField(blank=True, max_length=120, verbose_name='Referência interna')),
                ('invoice_number', models.CharField(blank=True, max_length=120, verbose_name='Fatura / recibo')),
                ('notes', models.TextField(blank=True, verbose_name='Observações')),
                ('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)),
                ('renewal', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='billing.renewal', verbose_name='Renovação')),
            ],
            options={
                'verbose_name': 'historical Pagamento',
                'verbose_name_plural': 'historical Pagamentos',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.AddIndex(
            model_name='renewal',
            index=models.Index(fields=['status', 'due_date'], name='billing_ren_status_3d12ec_idx'),
        ),
        migrations.AddConstraint(
            model_name='renewal',
            constraint=models.UniqueConstraint(fields=('service', 'due_date'), name='unique_service_due_date'),
        ),
        migrations.AddIndex(
            model_name='payment',
            index=models.Index(fields=['status', 'paid_at'], name='billing_pay_status_64681e_idx'),
        ),
    ]
