# Generated by Django 5.2.15 on 2026-06-15 13:52

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):

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

    operations = [
        migrations.AlterField(
            model_name='client',
            name='portal_access_enabled',
            field=models.BooleanField(default=False, verbose_name='Acesso ao portal ativo'),
        ),
        migrations.AlterField(
            model_name='client',
            name='status',
            field=models.CharField(choices=[('pending', 'A aguardar ativação'), ('active', 'Ativo'), ('special', 'Acompanhamento especial'), ('debt', 'Com dívida'), ('blocked', 'Bloqueado'), ('inactive', 'Inativo'), ('former', 'Cliente antigo')], db_index=True, default='active', max_length=20, verbose_name='Estado'),
        ),
        migrations.AlterField(
            model_name='historicalclient',
            name='portal_access_enabled',
            field=models.BooleanField(default=False, verbose_name='Acesso ao portal ativo'),
        ),
        migrations.AlterField(
            model_name='historicalclient',
            name='status',
            field=models.CharField(choices=[('pending', 'A aguardar ativação'), ('active', 'Ativo'), ('special', 'Acompanhamento especial'), ('debt', 'Com dívida'), ('blocked', 'Bloqueado'), ('inactive', 'Inativo'), ('former', 'Cliente antigo')], db_index=True, default='active', max_length=20, verbose_name='Estado'),
        ),
        migrations.CreateModel(
            name='HistoricalClientPortalAccess',
            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')),
                ('role', models.CharField(choices=[('owner', 'Responsável principal'), ('billing', 'Financeiro'), ('technical', 'Técnico'), ('viewer', 'Consulta')], default='owner', max_length=20, verbose_name='Perfil')),
                ('is_active', models.BooleanField(db_index=True, default=True, verbose_name='Acesso ativo')),
                ('can_view_financial', models.BooleanField(default=True, verbose_name='Pode consultar pagamentos')),
                ('can_view_documents', models.BooleanField(default=True, verbose_name='Pode consultar documentos')),
                ('can_manage_tickets', models.BooleanField(default=True, verbose_name='Pode criar e responder a tickets')),
                ('invited_at', models.DateTimeField(default=django.utils.timezone.now, verbose_name='Convidado em')),
                ('accepted_at', models.DateTimeField(blank=True, null=True, verbose_name='Acesso aceite em')),
                ('last_portal_login_at', models.DateTimeField(blank=True, null=True, verbose_name='Último acesso')),
                ('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)),
                ('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')),
            ],
            options={
                'verbose_name': 'historical Acesso ao portal do cliente',
                'verbose_name_plural': 'historical Acessos ao portal dos clientes',
                'ordering': ('-history_date', '-history_id'),
                'get_latest_by': ('history_date', 'history_id'),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name='ClientPortalAccess',
            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')),
                ('role', models.CharField(choices=[('owner', 'Responsável principal'), ('billing', 'Financeiro'), ('technical', 'Técnico'), ('viewer', 'Consulta')], default='owner', max_length=20, verbose_name='Perfil')),
                ('is_active', models.BooleanField(db_index=True, default=True, verbose_name='Acesso ativo')),
                ('can_view_financial', models.BooleanField(default=True, verbose_name='Pode consultar pagamentos')),
                ('can_view_documents', models.BooleanField(default=True, verbose_name='Pode consultar documentos')),
                ('can_manage_tickets', models.BooleanField(default=True, verbose_name='Pode criar e responder a tickets')),
                ('invited_at', models.DateTimeField(default=django.utils.timezone.now, verbose_name='Convidado em')),
                ('accepted_at', models.DateTimeField(blank=True, null=True, verbose_name='Acesso aceite em')),
                ('last_portal_login_at', models.DateTimeField(blank=True, null=True, verbose_name='Último acesso')),
                ('client', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='portal_accesses', to='clients.client', verbose_name='Cliente')),
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='client_portal_access', to=settings.AUTH_USER_MODEL, verbose_name='Utilizador')),
            ],
            options={
                'verbose_name': 'Acesso ao portal do cliente',
                'verbose_name_plural': 'Acessos ao portal dos clientes',
                'ordering': ['client__name', 'user__username'],
                'indexes': [models.Index(fields=['client', 'is_active'], name='clients_cli_client__de12e5_idx')],
                'constraints': [models.UniqueConstraint(fields=('client', 'user'), name='unique_client_portal_user')],
            },
        ),
    ]
