# Generated by Django 5.2.15 on 2026-06-15 15:10

import django.db.models.deletion
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='RecoveryCode',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('code_hash', models.CharField(max_length=255, verbose_name='Código protegido')),
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Criado em')),
                ('used_at', models.DateTimeField(blank=True, null=True, verbose_name='Utilizado em')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='k4w_recovery_codes', to=settings.AUTH_USER_MODEL, verbose_name='Utilizador')),
            ],
            options={
                'verbose_name': 'Código de recuperação',
                'verbose_name_plural': 'Códigos de recuperação',
                'ordering': ['used_at', 'created_at'],
            },
        ),
        migrations.CreateModel(
            name='SecurityEvent',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('event_type', models.CharField(choices=[('login_success', 'Login efetuado'), ('login_failed', 'Login falhado'), ('otp_success', 'Segundo fator validado'), ('otp_failed', 'Segundo fator inválido'), ('otp_enabled', '2FA ativado'), ('otp_disabled', '2FA desativado'), ('recovery_used', 'Código de recuperação utilizado'), ('recovery_regenerated', 'Códigos de recuperação regenerados'), ('profile_updated', 'Perfil atualizado')], db_index=True, max_length=40, verbose_name='Evento')),
                ('username_entered', models.CharField(blank=True, max_length=254, verbose_name='Identificador introduzido')),
                ('ip_address', models.GenericIPAddressField(blank=True, null=True, verbose_name='Endereço IP')),
                ('user_agent', models.CharField(blank=True, max_length=500, verbose_name='Navegador')),
                ('details', models.JSONField(blank=True, default=dict, verbose_name='Detalhes')),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True, verbose_name='Data')),
                ('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='k4w_security_events', to=settings.AUTH_USER_MODEL, verbose_name='Utilizador')),
            ],
            options={
                'verbose_name': 'Evento de segurança',
                'verbose_name_plural': 'Eventos de segurança',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='UserProfile',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('avatar', models.FileField(blank=True, upload_to='avatars/%Y/%m/', verbose_name='Fotografia')),
                ('phone', models.CharField(blank=True, max_length=40, verbose_name='Telefone')),
                ('job_title', models.CharField(blank=True, max_length=120, verbose_name='Função')),
                ('two_factor_required', models.BooleanField(default=False, help_text='Quando ativo, este utilizador só entra depois de validar um código temporário.', verbose_name='Exigir autenticação de dois fatores')),
                ('last_two_factor_at', models.DateTimeField(blank=True, null=True, verbose_name='Última validação 2FA')),
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Criado em')),
                ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Atualizado em')),
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='k4w_profile', to=settings.AUTH_USER_MODEL, verbose_name='Utilizador')),
            ],
            options={
                'verbose_name': 'Perfil de utilizador',
                'verbose_name_plural': 'Perfis de utilizadores',
            },
        ),
    ]
