# Generated by Django 5.2.8 on 2025-11-29 18:53

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


class Migration(migrations.Migration):

    dependencies = [
        ('users', '0007_add_is_sandbox_to_user'),
    ]

    operations = [
        migrations.AddField(
            model_name='user',
            name='mfa_backup_codes',
            field=models.JSONField(blank=True, default=list, help_text='List of hashed backup codes for account recovery'),
        ),
        migrations.AddField(
            model_name='user',
            name='mfa_backup_codes_generated_at',
            field=models.DateTimeField(blank=True, help_text='When backup codes were last generated', null=True),
        ),
        migrations.AddField(
            model_name='user',
            name='mfa_enabled',
            field=models.BooleanField(default=False, help_text='Whether two-factor authentication is enabled for this user'),
        ),
        migrations.AddField(
            model_name='user',
            name='mfa_method',
            field=models.CharField(choices=[('NONE', 'None'), ('SMS', 'SMS (Twilio)'), ('TOTP', 'Authenticator App'), ('BOTH', 'Both SMS and Authenticator')], default='NONE', help_text='Preferred 2FA method', max_length=20),
        ),
        migrations.AddField(
            model_name='user',
            name='phone_verified',
            field=models.BooleanField(default=False, help_text='Whether user has verified their phone number'),
        ),
        migrations.AddField(
            model_name='user',
            name='totp_secret',
            field=models.CharField(blank=True, help_text='Encrypted TOTP secret for authenticator apps', max_length=64),
        ),
        migrations.AddField(
            model_name='user',
            name='totp_verified',
            field=models.BooleanField(default=False, help_text='Whether TOTP setup has been verified'),
        ),
        migrations.CreateModel(
            name='MFAVerificationCode',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('code', models.CharField(help_text='6-digit verification code', max_length=6)),
                ('purpose', models.CharField(choices=[('LOGIN', 'Login Verification'), ('SETUP', 'MFA Setup'), ('PHONE_VERIFY', 'Phone Verification'), ('DISABLE', 'Disable MFA')], default='LOGIN', max_length=20)),
                ('method', models.CharField(choices=[('SMS', 'SMS'), ('TOTP', 'TOTP')], default='SMS', max_length=10)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('expires_at', models.DateTimeField()),
                ('used', models.BooleanField(default=False)),
                ('attempts', models.IntegerField(default=0, help_text='Number of failed verification attempts')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='mfa_codes', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['user', 'purpose', 'used'], name='users_mfave_user_id_6b7cf0_idx'), models.Index(fields=['expires_at'], name='users_mfave_expires_b8c650_idx')],
            },
        ),
        migrations.CreateModel(
            name='TrustedDevice',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('device_hash', models.CharField(help_text='Hash of device fingerprint (IP + User-Agent + other factors)', max_length=64)),
                ('name', models.CharField(blank=True, help_text="User-friendly device name (e.g., 'Chrome on MacBook')", max_length=100)),
                ('ip_address', models.GenericIPAddressField(blank=True, null=True)),
                ('user_agent', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('last_used_at', models.DateTimeField(auto_now=True)),
                ('expires_at', models.DateTimeField()),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='trusted_devices', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['-last_used_at'],
                'indexes': [models.Index(fields=['user', 'device_hash'], name='users_trust_user_id_a68866_idx'), models.Index(fields=['expires_at'], name='users_trust_expires_d87de2_idx')],
                'unique_together': {('user', 'device_hash')},
            },
        ),
    ]
