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

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


class Migration(migrations.Migration):

    initial = True

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

    operations = [
        migrations.CreateModel(
            name='HistoricalSupportTicket',
            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')),
                ('subject', models.CharField(max_length=220, verbose_name='Assunto')),
                ('category', models.CharField(choices=[('billing', 'Faturação / pagamento'), ('domain', 'Domínio'), ('hosting', 'Alojamento'), ('email', 'Email'), ('website', 'Website'), ('technical', 'Questão técnica'), ('change', 'Pedido de alteração'), ('other', 'Outro')], default='other', max_length=25, verbose_name='Categoria')),
                ('priority', models.CharField(choices=[('low', 'Baixa'), ('normal', 'Normal'), ('high', 'Alta'), ('urgent', 'Urgente')], db_index=True, default='normal', max_length=15, verbose_name='Prioridade')),
                ('status', models.CharField(choices=[('open', 'Aberto'), ('in_progress', 'Em tratamento'), ('waiting_client', 'A aguardar cliente'), ('waiting_internal', 'A aguardar internamente'), ('resolved', 'Resolvido'), ('closed', 'Fechado')], db_index=True, default='open', max_length=25, verbose_name='Estado')),
                ('channel', models.CharField(choices=[('portal', 'Portal do cliente'), ('email', 'Email'), ('phone', 'Telefone'), ('internal', 'Registo interno')], default='internal', max_length=20, verbose_name='Origem')),
                ('description', models.TextField(verbose_name='Descrição')),
                ('due_date', models.DateField(blank=True, db_index=True, null=True, verbose_name='Data limite')),
                ('last_activity_at', models.DateTimeField(db_index=True, default=django.utils.timezone.now, verbose_name='Última atividade')),
                ('closed_at', models.DateTimeField(blank=True, null=True, verbose_name='Fechado em')),
                ('client_visible', models.BooleanField(default=True, help_text='Deixa o registo preparado para ser mostrado quando a área do cliente for criada.', verbose_name='Visível na futura área do cliente')),
                ('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)),
                ('assigned_to', 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='Responsável')),
                ('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)),
                ('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 Pedido de suporte',
                'verbose_name_plural': 'historical Pedidos de suporte',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='SupportTicket',
            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')),
                ('subject', models.CharField(max_length=220, verbose_name='Assunto')),
                ('category', models.CharField(choices=[('billing', 'Faturação / pagamento'), ('domain', 'Domínio'), ('hosting', 'Alojamento'), ('email', 'Email'), ('website', 'Website'), ('technical', 'Questão técnica'), ('change', 'Pedido de alteração'), ('other', 'Outro')], default='other', max_length=25, verbose_name='Categoria')),
                ('priority', models.CharField(choices=[('low', 'Baixa'), ('normal', 'Normal'), ('high', 'Alta'), ('urgent', 'Urgente')], db_index=True, default='normal', max_length=15, verbose_name='Prioridade')),
                ('status', models.CharField(choices=[('open', 'Aberto'), ('in_progress', 'Em tratamento'), ('waiting_client', 'A aguardar cliente'), ('waiting_internal', 'A aguardar internamente'), ('resolved', 'Resolvido'), ('closed', 'Fechado')], db_index=True, default='open', max_length=25, verbose_name='Estado')),
                ('channel', models.CharField(choices=[('portal', 'Portal do cliente'), ('email', 'Email'), ('phone', 'Telefone'), ('internal', 'Registo interno')], default='internal', max_length=20, verbose_name='Origem')),
                ('description', models.TextField(verbose_name='Descrição')),
                ('due_date', models.DateField(blank=True, db_index=True, null=True, verbose_name='Data limite')),
                ('last_activity_at', models.DateTimeField(db_index=True, default=django.utils.timezone.now, verbose_name='Última atividade')),
                ('closed_at', models.DateTimeField(blank=True, null=True, verbose_name='Fechado em')),
                ('client_visible', models.BooleanField(default=True, help_text='Deixa o registo preparado para ser mostrado quando a área do cliente for criada.', verbose_name='Visível na futura área do cliente')),
                ('assigned_to', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='assigned_support_tickets', to=settings.AUTH_USER_MODEL, verbose_name='Responsável')),
                ('client', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='support_tickets', to='clients.client', verbose_name='Cliente')),
                ('service', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='support_tickets', to='services.service', verbose_name='Serviço')),
            ],
            options={
                'verbose_name': 'Pedido de suporte',
                'verbose_name_plural': 'Pedidos de suporte',
                'ordering': ['status', '-priority', '-last_activity_at'],
            },
        ),
        migrations.CreateModel(
            name='SupportMessage',
            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')),
                ('author_type', models.CharField(choices=[('staff', 'Equipa'), ('client', 'Cliente'), ('system', 'Sistema')], default='staff', max_length=15, verbose_name='Autor')),
                ('author_name', models.CharField(blank=True, max_length=180, verbose_name='Nome apresentado')),
                ('author_email', models.EmailField(blank=True, max_length=254, verbose_name='Email')),
                ('message', models.TextField(verbose_name='Mensagem')),
                ('is_internal', models.BooleanField(default=False, help_text='As notas internas nunca serão apresentadas ao cliente.', verbose_name='Nota interna')),
                ('staff_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='support_messages', to=settings.AUTH_USER_MODEL, verbose_name='Utilizador interno')),
                ('ticket', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='messages', to='support.supportticket', verbose_name='Pedido')),
            ],
            options={
                'verbose_name': 'Mensagem de suporte',
                'verbose_name_plural': 'Mensagens de suporte',
                'ordering': ['created_at'],
            },
        ),
        migrations.CreateModel(
            name='HistoricalSupportMessage',
            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')),
                ('author_type', models.CharField(choices=[('staff', 'Equipa'), ('client', 'Cliente'), ('system', 'Sistema')], default='staff', max_length=15, verbose_name='Autor')),
                ('author_name', models.CharField(blank=True, max_length=180, verbose_name='Nome apresentado')),
                ('author_email', models.EmailField(blank=True, max_length=254, verbose_name='Email')),
                ('message', models.TextField(verbose_name='Mensagem')),
                ('is_internal', models.BooleanField(default=False, help_text='As notas internas nunca serão apresentadas ao cliente.', verbose_name='Nota interna')),
                ('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)),
                ('staff_user', 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='Utilizador interno')),
                ('ticket', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='support.supportticket', verbose_name='Pedido')),
            ],
            options={
                'verbose_name': 'historical Mensagem de suporte',
                'verbose_name_plural': 'historical Mensagens de suporte',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.AddIndex(
            model_name='supportticket',
            index=models.Index(fields=['status', 'priority', 'last_activity_at'], name='support_sup_status_3ca7ec_idx'),
        ),
        migrations.AddIndex(
            model_name='supportticket',
            index=models.Index(fields=['client', 'status'], name='support_sup_client__068cd5_idx'),
        ),
    ]
