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

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 = [
        ('billing', '0001_initial'),
        ('clients', '0001_initial'),
        ('services', '0001_initial'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='NotificationTemplate',
            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')),
                ('code', models.SlugField(max_length=80, unique=True, verbose_name='Código')),
                ('notification_type', models.CharField(choices=[('renewal_30', 'Renovação — 30 dias'), ('renewal_15', 'Renovação — 15 dias'), ('renewal_7', 'Renovação — 7 dias'), ('due', 'No dia da renovação'), ('overdue', 'Serviço vencido'), ('payment_received', 'Confirmação de pagamento'), ('renewal_confirmed', 'Confirmação de renovação'), ('general', 'Mensagem geral')], max_length=30, verbose_name='Tipo')),
                ('subject_template', models.CharField(max_length=250, verbose_name='Assunto')),
                ('body_template', models.TextField(help_text='Variáveis previstas: {cliente}, {servico}, {dominio}, {data_renovacao}, {valor}, {metodo_pagamento}.', verbose_name='Mensagem')),
                ('is_active', models.BooleanField(default=True, verbose_name='Ativo')),
            ],
            options={
                'verbose_name': 'Modelo de notificação',
                'verbose_name_plural': 'Modelos de notificação',
                'ordering': ['notification_type', 'code'],
            },
        ),
        migrations.CreateModel(
            name='HistoricalNotificationTemplate',
            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')),
                ('code', models.SlugField(max_length=80, verbose_name='Código')),
                ('notification_type', models.CharField(choices=[('renewal_30', 'Renovação — 30 dias'), ('renewal_15', 'Renovação — 15 dias'), ('renewal_7', 'Renovação — 7 dias'), ('due', 'No dia da renovação'), ('overdue', 'Serviço vencido'), ('payment_received', 'Confirmação de pagamento'), ('renewal_confirmed', 'Confirmação de renovação'), ('general', 'Mensagem geral')], max_length=30, verbose_name='Tipo')),
                ('subject_template', models.CharField(max_length=250, verbose_name='Assunto')),
                ('body_template', models.TextField(help_text='Variáveis previstas: {cliente}, {servico}, {dominio}, {data_renovacao}, {valor}, {metodo_pagamento}.', verbose_name='Mensagem')),
                ('is_active', models.BooleanField(default=True, verbose_name='Ativo')),
                ('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)),
            ],
            options={
                'verbose_name': 'historical Modelo de notificação',
                'verbose_name_plural': 'historical Modelos de notificação',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='HistoricalNotificationLog',
            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')),
                ('channel', models.CharField(choices=[('email', 'Email'), ('sms', 'SMS'), ('internal', 'Alerta interno'), ('portal', 'Portal do cliente')], default='email', max_length=20, verbose_name='Canal')),
                ('recipient', models.CharField(max_length=250, verbose_name='Destinatário')),
                ('subject', models.CharField(blank=True, max_length=250, verbose_name='Assunto')),
                ('body', models.TextField(verbose_name='Mensagem')),
                ('status', models.CharField(choices=[('draft', 'Rascunho'), ('scheduled', 'Agendado'), ('sent', 'Enviado'), ('failed', 'Falhou'), ('cancelled', 'Cancelado')], db_index=True, default='draft', max_length=20, verbose_name='Estado')),
                ('scheduled_for', models.DateTimeField(blank=True, null=True, verbose_name='Agendado para')),
                ('sent_at', models.DateTimeField(blank=True, null=True, verbose_name='Enviado em')),
                ('error_message', models.TextField(blank=True, verbose_name='Erro')),
                ('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)),
                ('client', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='clients.client', verbose_name='Cliente')),
                ('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')),
                ('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')),
                ('template', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='notifications.notificationtemplate', verbose_name='Modelo')),
            ],
            options={
                'verbose_name': 'historical Notificação',
                'verbose_name_plural': 'historical Notificações',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='NotificationLog',
            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')),
                ('channel', models.CharField(choices=[('email', 'Email'), ('sms', 'SMS'), ('internal', 'Alerta interno'), ('portal', 'Portal do cliente')], default='email', max_length=20, verbose_name='Canal')),
                ('recipient', models.CharField(max_length=250, verbose_name='Destinatário')),
                ('subject', models.CharField(blank=True, max_length=250, verbose_name='Assunto')),
                ('body', models.TextField(verbose_name='Mensagem')),
                ('status', models.CharField(choices=[('draft', 'Rascunho'), ('scheduled', 'Agendado'), ('sent', 'Enviado'), ('failed', 'Falhou'), ('cancelled', 'Cancelado')], db_index=True, default='draft', max_length=20, verbose_name='Estado')),
                ('scheduled_for', models.DateTimeField(blank=True, null=True, verbose_name='Agendado para')),
                ('sent_at', models.DateTimeField(blank=True, null=True, verbose_name='Enviado em')),
                ('error_message', models.TextField(blank=True, verbose_name='Erro')),
                ('client', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='notifications', to='clients.client', verbose_name='Cliente')),
                ('renewal', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='notifications', to='billing.renewal', verbose_name='Renovação')),
                ('service', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='notifications', to='services.service', verbose_name='Serviço')),
                ('template', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='logs', to='notifications.notificationtemplate', verbose_name='Modelo')),
            ],
            options={
                'verbose_name': 'Notificação',
                'verbose_name_plural': 'Notificações',
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['status', 'scheduled_for'], name='notificatio_status_2e04f4_idx')],
            },
        ),
    ]
