# Generated by Django 4.2.16 on 2025-09-02 21:22

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='LoginAttempt',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True, help_text='Timestamp when this record was created')),
                ('updated_at', models.DateTimeField(auto_now=True, help_text='Timestamp when this record was last modified')),
                ('username', models.CharField(max_length=150)),
                ('ip_address', models.GenericIPAddressField()),
                ('user_agent', models.TextField(blank=True)),
                ('success', models.BooleanField()),
                ('failure_reason', models.CharField(blank=True, max_length=100)),
            ],
            options={
                'verbose_name': 'Login Attempt',
                'verbose_name_plural': 'Login Attempts',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='UserSession',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True, help_text='Timestamp when this record was created')),
                ('updated_at', models.DateTimeField(auto_now=True, help_text='Timestamp when this record was last modified')),
                ('session_key', models.CharField(max_length=40, unique=True)),
                ('ip_address', models.GenericIPAddressField()),
                ('user_agent', models.TextField(blank=True)),
                ('is_active', models.BooleanField(default=True)),
                ('last_activity', models.DateTimeField(auto_now=True)),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'User Session',
                'verbose_name_plural': 'User Sessions',
                'ordering': ['-last_activity'],
            },
        ),
        migrations.CreateModel(
            name='UserProfile',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True, help_text='Timestamp when this record was created')),
                ('updated_at', models.DateTimeField(auto_now=True, help_text='Timestamp when this record was last modified')),
                ('totp_secret', models.CharField(blank=True, help_text='TOTP secret key for 2FA', max_length=32)),
                ('is_2fa_enabled', models.BooleanField(default=False, help_text='Whether 2FA is enabled for this user')),
                ('backup_codes', models.JSONField(default=list, help_text='Backup codes for 2FA recovery')),
                ('failed_login_attempts', models.PositiveIntegerField(default=0, help_text='Number of consecutive failed login attempts')),
                ('account_locked_until', models.DateTimeField(blank=True, help_text='Account lockout expiration time', null=True)),
                ('last_login_ip', models.GenericIPAddressField(blank=True, help_text='IP address of last successful login', null=True)),
                ('last_password_change', models.DateTimeField(blank=True, help_text='Timestamp of last password change', null=True)),
                ('password_reset_required', models.BooleanField(default=False, help_text='Whether user must reset password on next login')),
                ('max_concurrent_sessions', models.PositiveIntegerField(default=3, help_text='Maximum number of concurrent sessions allowed')),
                ('session_timeout_minutes', models.PositiveIntegerField(default=480, help_text='Session timeout in minutes')),
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='security_profile', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'User Security Profile',
                'verbose_name_plural': 'User Security Profiles',
            },
        ),
    ]
