# Generated by Django 5.2.15 on 2026-06-15 14:19

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='FormTemplate',
            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')),
                ('name', models.CharField(max_length=180, verbose_name='Nome')),
                ('code', models.SlugField(max_length=100, unique=True, verbose_name='Código')),
                ('purpose', models.CharField(choices=[('client_onboarding', 'Adesão / dados do cliente'), ('support', 'Pedido de suporte'), ('domain', 'Pedido de domínio'), ('hosting', 'Pedido de alojamento'), ('website', 'Briefing de website'), ('payment', 'Informação de pagamento'), ('maintenance', 'Pedido de manutenção'), ('satisfaction', 'Satisfação / feedback'), ('general', 'Formulário geral')], db_index=True, default='general', max_length=30, verbose_name='Finalidade')),
                ('description', models.TextField(blank=True, verbose_name='Descrição')),
                ('intro_text', models.TextField(blank=True, verbose_name='Texto introdutório')),
                ('success_message', models.TextField(default='Formulário recebido com sucesso.', verbose_name='Mensagem de sucesso')),
                ('version', models.PositiveSmallIntegerField(default=1, verbose_name='Versão')),
                ('is_active', models.BooleanField(db_index=True, default=True, verbose_name='Ativo')),
                ('visible_to_clients', models.BooleanField(default=False, verbose_name='Disponível no portal do cliente')),
                ('requires_authentication', models.BooleanField(default=True, verbose_name='Exige autenticação')),
                ('sort_order', models.PositiveSmallIntegerField(default=100, verbose_name='Ordem')),
            ],
            options={
                'verbose_name': 'Template de formulário',
                'verbose_name_plural': 'Templates de formulários',
                'ordering': ['sort_order', 'name'],
            },
        ),
        migrations.CreateModel(
            name='TemplateCategory',
            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')),
                ('name', models.CharField(max_length=120, unique=True, verbose_name='Nome')),
                ('code', models.SlugField(max_length=80, unique=True, verbose_name='Código')),
                ('description', models.TextField(blank=True, verbose_name='Descrição')),
                ('icon', models.CharField(default='folder_copy', max_length=80, verbose_name='Ícone Material')),
                ('tone', models.CharField(choices=[('yellow', 'Amarelo Kreate4Web'), ('blue', 'Azul'), ('green', 'Verde'), ('violet', 'Violeta'), ('orange', 'Laranja'), ('grey', 'Cinzento')], default='yellow', max_length=20, verbose_name='Cor')),
                ('sort_order', models.PositiveSmallIntegerField(default=100, verbose_name='Ordem')),
                ('is_active', models.BooleanField(db_index=True, default=True, verbose_name='Ativa')),
            ],
            options={
                'verbose_name': 'Categoria de templates',
                'verbose_name_plural': 'Categorias de templates',
                'ordering': ['sort_order', 'name'],
            },
        ),
        migrations.CreateModel(
            name='HistoricalFormTemplateField',
            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')),
                ('label', models.CharField(max_length=180, verbose_name='Etiqueta')),
                ('key', models.SlugField(max_length=100, verbose_name='Chave')),
                ('field_type', models.CharField(choices=[('text', 'Texto curto'), ('textarea', 'Texto longo'), ('email', 'Email'), ('phone', 'Telefone'), ('number', 'Número'), ('date', 'Data'), ('url', 'URL'), ('select', 'Lista de opções'), ('radio', 'Escolha única'), ('checkbox', 'Caixa de seleção'), ('file', 'Ficheiro')], default='text', max_length=20, verbose_name='Tipo de campo')),
                ('help_text', models.CharField(blank=True, max_length=300, verbose_name='Ajuda')),
                ('placeholder', models.CharField(blank=True, max_length=250, verbose_name='Placeholder')),
                ('required', models.BooleanField(default=False, verbose_name='Obrigatório')),
                ('options', models.TextField(blank=True, help_text='Uma opção por linha para listas e escolhas.', verbose_name='Opções')),
                ('default_value', models.CharField(blank=True, max_length=250, verbose_name='Valor predefinido')),
                ('sort_order', models.PositiveSmallIntegerField(default=100, verbose_name='Ordem')),
                ('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)),
                ('form_template', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='template_library.formtemplate', verbose_name='Formulário')),
                ('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 Campo de formulário',
                'verbose_name_plural': 'historical Campos de formulário',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='HistoricalTemplateCategory',
            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')),
                ('name', models.CharField(db_index=True, max_length=120, verbose_name='Nome')),
                ('code', models.SlugField(max_length=80, verbose_name='Código')),
                ('description', models.TextField(blank=True, verbose_name='Descrição')),
                ('icon', models.CharField(default='folder_copy', max_length=80, verbose_name='Ícone Material')),
                ('tone', models.CharField(choices=[('yellow', 'Amarelo Kreate4Web'), ('blue', 'Azul'), ('green', 'Verde'), ('violet', 'Violeta'), ('orange', 'Laranja'), ('grey', 'Cinzento')], default='yellow', max_length=20, verbose_name='Cor')),
                ('sort_order', models.PositiveSmallIntegerField(default=100, verbose_name='Ordem')),
                ('is_active', models.BooleanField(db_index=True, default=True, verbose_name='Ativa')),
                ('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 Categoria de templates',
                'verbose_name_plural': 'historical Categorias de templates',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='ReusableTemplate',
            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')),
                ('name', models.CharField(max_length=180, verbose_name='Nome')),
                ('code', models.SlugField(max_length=100, unique=True, verbose_name='Código')),
                ('kind', models.CharField(choices=[('message', 'Mensagem geral'), ('ticket_reply', 'Resposta de ticket'), ('portal_notice', 'Aviso no portal'), ('document', 'Documento'), ('contract', 'Contrato'), ('report', 'Relatório'), ('checklist', 'Checklist'), ('quote', 'Orçamento'), ('invoice_note', 'Nota de faturação'), ('technical', 'Conteúdo técnico')], db_index=True, default='message', max_length=30, verbose_name='Tipo')),
                ('description', models.TextField(blank=True, verbose_name='Descrição')),
                ('subject_template', models.CharField(blank=True, max_length=250, verbose_name='Título / assunto')),
                ('body_template', models.TextField(verbose_name='Conteúdo em texto')),
                ('html_template', models.TextField(blank=True, verbose_name='Conteúdo HTML')),
                ('variables', models.TextField(blank=True, help_text='Uma variável por linha, por exemplo: {cliente} — nome do cliente.', verbose_name='Variáveis disponíveis')),
                ('example_context', models.JSONField(blank=True, default=dict, help_text='Valores usados na pré-visualização. Ex.: {"cliente": "Acácia Studio"}.', verbose_name='Dados de exemplo')),
                ('is_active', models.BooleanField(db_index=True, default=True, verbose_name='Ativo')),
                ('is_default', models.BooleanField(default=False, verbose_name='Modelo predefinido')),
                ('visible_to_clients', models.BooleanField(default=False, verbose_name='Pode ser usado no portal do cliente')),
                ('usage_count', models.PositiveIntegerField(default=0, editable=False, verbose_name='Utilizações')),
                ('last_used_at', models.DateTimeField(blank=True, editable=False, null=True, verbose_name='Última utilização')),
                ('category', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='content_templates', to='template_library.templatecategory', verbose_name='Categoria')),
            ],
            options={
                'verbose_name': 'Template reutilizável',
                'verbose_name_plural': 'Templates reutilizáveis',
                'ordering': ['kind', 'name'],
            },
        ),
        migrations.CreateModel(
            name='HistoricalReusableTemplate',
            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')),
                ('name', models.CharField(max_length=180, verbose_name='Nome')),
                ('code', models.SlugField(max_length=100, verbose_name='Código')),
                ('kind', models.CharField(choices=[('message', 'Mensagem geral'), ('ticket_reply', 'Resposta de ticket'), ('portal_notice', 'Aviso no portal'), ('document', 'Documento'), ('contract', 'Contrato'), ('report', 'Relatório'), ('checklist', 'Checklist'), ('quote', 'Orçamento'), ('invoice_note', 'Nota de faturação'), ('technical', 'Conteúdo técnico')], db_index=True, default='message', max_length=30, verbose_name='Tipo')),
                ('description', models.TextField(blank=True, verbose_name='Descrição')),
                ('subject_template', models.CharField(blank=True, max_length=250, verbose_name='Título / assunto')),
                ('body_template', models.TextField(verbose_name='Conteúdo em texto')),
                ('html_template', models.TextField(blank=True, verbose_name='Conteúdo HTML')),
                ('variables', models.TextField(blank=True, help_text='Uma variável por linha, por exemplo: {cliente} — nome do cliente.', verbose_name='Variáveis disponíveis')),
                ('example_context', models.JSONField(blank=True, default=dict, help_text='Valores usados na pré-visualização. Ex.: {"cliente": "Acácia Studio"}.', verbose_name='Dados de exemplo')),
                ('is_active', models.BooleanField(db_index=True, default=True, verbose_name='Ativo')),
                ('is_default', models.BooleanField(default=False, verbose_name='Modelo predefinido')),
                ('visible_to_clients', models.BooleanField(default=False, verbose_name='Pode ser usado no portal do cliente')),
                ('usage_count', models.PositiveIntegerField(default=0, editable=False, verbose_name='Utilizações')),
                ('last_used_at', models.DateTimeField(blank=True, editable=False, null=True, verbose_name='Última utilizaçã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)),
                ('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('category', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='template_library.templatecategory', verbose_name='Categoria')),
            ],
            options={
                'verbose_name': 'historical Template reutilizável',
                'verbose_name_plural': 'historical Templates reutilizáveis',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='HistoricalFormTemplate',
            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')),
                ('name', models.CharField(max_length=180, verbose_name='Nome')),
                ('code', models.SlugField(max_length=100, verbose_name='Código')),
                ('purpose', models.CharField(choices=[('client_onboarding', 'Adesão / dados do cliente'), ('support', 'Pedido de suporte'), ('domain', 'Pedido de domínio'), ('hosting', 'Pedido de alojamento'), ('website', 'Briefing de website'), ('payment', 'Informação de pagamento'), ('maintenance', 'Pedido de manutenção'), ('satisfaction', 'Satisfação / feedback'), ('general', 'Formulário geral')], db_index=True, default='general', max_length=30, verbose_name='Finalidade')),
                ('description', models.TextField(blank=True, verbose_name='Descrição')),
                ('intro_text', models.TextField(blank=True, verbose_name='Texto introdutório')),
                ('success_message', models.TextField(default='Formulário recebido com sucesso.', verbose_name='Mensagem de sucesso')),
                ('version', models.PositiveSmallIntegerField(default=1, verbose_name='Versão')),
                ('is_active', models.BooleanField(db_index=True, default=True, verbose_name='Ativo')),
                ('visible_to_clients', models.BooleanField(default=False, verbose_name='Disponível no portal do cliente')),
                ('requires_authentication', models.BooleanField(default=True, verbose_name='Exige autenticação')),
                ('sort_order', models.PositiveSmallIntegerField(default=100, verbose_name='Ordem')),
                ('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)),
                ('category', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='template_library.templatecategory', verbose_name='Categoria')),
            ],
            options={
                'verbose_name': 'historical Template de formulário',
                'verbose_name_plural': 'historical Templates de formulários',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.AddField(
            model_name='formtemplate',
            name='category',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='form_templates', to='template_library.templatecategory', verbose_name='Categoria'),
        ),
        migrations.CreateModel(
            name='TemplateUsage',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('action', models.CharField(choices=[('preview', 'Pré-visualização'), ('copy', 'Copiado'), ('generated', 'Documento gerado'), ('sent', 'Usado em comunicação')], default='preview', max_length=20, verbose_name='Ação')),
                ('context', models.JSONField(blank=True, default=dict, verbose_name='Contexto')),
                ('used_at', models.DateTimeField(auto_now_add=True, db_index=True, verbose_name='Utilizado em')),
                ('form_template', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='usage_logs', to='template_library.formtemplate', verbose_name='Formulário')),
                ('reusable_template', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='usage_logs', to='template_library.reusabletemplate', verbose_name='Template reutilizável')),
                ('used_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='template_usages', to=settings.AUTH_USER_MODEL, verbose_name='Utilizador')),
            ],
            options={
                'verbose_name': 'Utilização de template',
                'verbose_name_plural': 'Utilizações de templates',
                'ordering': ['-used_at'],
            },
        ),
        migrations.CreateModel(
            name='FormTemplateField',
            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')),
                ('label', models.CharField(max_length=180, verbose_name='Etiqueta')),
                ('key', models.SlugField(max_length=100, verbose_name='Chave')),
                ('field_type', models.CharField(choices=[('text', 'Texto curto'), ('textarea', 'Texto longo'), ('email', 'Email'), ('phone', 'Telefone'), ('number', 'Número'), ('date', 'Data'), ('url', 'URL'), ('select', 'Lista de opções'), ('radio', 'Escolha única'), ('checkbox', 'Caixa de seleção'), ('file', 'Ficheiro')], default='text', max_length=20, verbose_name='Tipo de campo')),
                ('help_text', models.CharField(blank=True, max_length=300, verbose_name='Ajuda')),
                ('placeholder', models.CharField(blank=True, max_length=250, verbose_name='Placeholder')),
                ('required', models.BooleanField(default=False, verbose_name='Obrigatório')),
                ('options', models.TextField(blank=True, help_text='Uma opção por linha para listas e escolhas.', verbose_name='Opções')),
                ('default_value', models.CharField(blank=True, max_length=250, verbose_name='Valor predefinido')),
                ('sort_order', models.PositiveSmallIntegerField(default=100, verbose_name='Ordem')),
                ('is_active', models.BooleanField(default=True, verbose_name='Ativo')),
                ('form_template', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='fields', to='template_library.formtemplate', verbose_name='Formulário')),
            ],
            options={
                'verbose_name': 'Campo de formulário',
                'verbose_name_plural': 'Campos de formulário',
                'ordering': ['sort_order', 'id'],
                'constraints': [models.UniqueConstraint(fields=('form_template', 'key'), name='unique_form_template_field_key')],
            },
        ),
        migrations.AddIndex(
            model_name='reusabletemplate',
            index=models.Index(fields=['kind', 'is_active'], name='template_li_kind_d18c3a_idx'),
        ),
        migrations.AddConstraint(
            model_name='reusabletemplate',
            constraint=models.UniqueConstraint(condition=models.Q(('is_default', True)), fields=('kind',), name='one_default_reusable_template_per_kind'),
        ),
        migrations.AddIndex(
            model_name='formtemplate',
            index=models.Index(fields=['purpose', 'is_active'], name='template_li_purpose_b38563_idx'),
        ),
    ]
