# Generated by Django 5.2.7 on 2025-10-06 07:51

import django.db.models.deletion
import django_auth_recovery_codes.app_settings
import django_auth_recovery_codes.base_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='RecoveryCodeAuditScheduler',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('enable_scheduler', models.BooleanField(default=True)),
                ('retention_days', models.PositiveBigIntegerField(default=30)),
                ('run_at', models.DateTimeField()),
                ('schedule_type', models.CharField(choices=[('O', 'Once'), ('H', 'Hourly'), ('D', 'Daily'), ('W', 'Weekly'), ('M', 'Monthly'), ('Q', 'Quarterly'), ('Y', 'Yearly')], default='D', help_text='Select how often this task should run.', max_length=1)),
                ('next_run', models.DateTimeField(blank=True, null=True)),
                ('deleted_count', models.PositiveIntegerField(default=0)),
                ('status', models.CharField(choices=[('s', 'Success'), ('f', 'Failure'), ('d', 'Deleted'), ('p', 'Pending')], default='p', max_length=1)),
                ('error_message', models.TextField(blank=True, editable=False, null=True)),
                ('use_with_logger', models.BooleanField(default=django_auth_recovery_codes.base_models.get_default_logger, help_text="If True, the scheduler will use a logger to record the sending of emails. Default value comes from the setting 'DJANGO_AUTH_RECOVERY_CODE_PURGE_DELETE_SCHEDULER_USE_LOGGER'.")),
                ('name', models.CharField(default='Remove Recovery code audit_14064a3b33cd47d387', max_length=180, unique=True)),
            ],
            options={
                'ordering': ['-run_at'],
                'abstract': False,
            },
        ),
        migrations.CreateModel(
            name='RecoveryCodeCleanUpScheduler',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('enable_scheduler', models.BooleanField(default=True)),
                ('retention_days', models.PositiveBigIntegerField(default=30)),
                ('run_at', models.DateTimeField()),
                ('schedule_type', models.CharField(choices=[('O', 'Once'), ('H', 'Hourly'), ('D', 'Daily'), ('W', 'Weekly'), ('M', 'Monthly'), ('Q', 'Quarterly'), ('Y', 'Yearly')], default='D', help_text='Select how often this task should run.', max_length=1)),
                ('status', models.CharField(choices=[('s', 'Success'), ('f', 'Failure'), ('d', 'Deleted'), ('p', 'Pending')], default='p', max_length=1)),
                ('error_message', models.TextField(blank=True, editable=False, null=True)),
                ('use_with_logger', models.BooleanField(default=django_auth_recovery_codes.base_models.get_default_logger, help_text="If True, the scheduler will use a logger to record the sending of emails. Default value comes from the setting 'DJANGO_AUTH_RECOVERY_CODE_PURGE_DELETE_SCHEDULER_USE_LOGGER'.")),
                ('name', models.CharField(default='Purge Expired Recovery Codes_98d811e634c146dca4', max_length=180, unique=True)),
                ('bulk_delete', models.BooleanField(default=True)),
                ('delete_empty_batch', models.BooleanField(default=True)),
                ('next_run', models.DateTimeField(blank=True, null=True)),
                ('deleted_count', models.PositiveIntegerField(default=0, editable=False)),
            ],
            options={
                'ordering': ['-run_at'],
                'abstract': False,
            },
        ),
        migrations.CreateModel(
            name='RecoveryCodeEmailLog',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('from_email', models.EmailField(db_index=True, max_length=100)),
                ('to_email', models.EmailField(db_index=True, max_length=200)),
                ('subject', models.CharField(max_length=100)),
                ('sent_on', models.DateTimeField(auto_now_add=True)),
                ('email_body', models.TextField()),
                ('status', models.CharField(max_length=50)),
                ('created_on', models.DateTimeField(auto_now_add=True)),
            ],
            options={
                'abstract': False,
            },
        ),
        migrations.CreateModel(
            name='RecoveryCodePurgeHistory',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(default='Recovery code purged history log', max_length=128)),
                ('timestamp', models.DateTimeField(auto_now_add=True)),
                ('total_codes_purged', models.PositiveIntegerField(default=0)),
                ('total_batches_purged', models.PositiveIntegerField(default=0)),
                ('retention_days', models.PositiveIntegerField(default=30)),
            ],
            options={
                'verbose_name': 'RecoveryCodePurgeHistory',
                'verbose_name_plural': 'RecoveryCodePurgeHistories',
            },
        ),
        migrations.CreateModel(
            name='LoginRateLimiter',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('last_attempt', models.DateTimeField(auto_now=True)),
                ('cooldown_seconds', models.PositiveSmallIntegerField(default=django_auth_recovery_codes.app_settings.default_cooldown_seconds, help_text='The number of seconds before a new request can be made. Default valued used from the settings.DJANGO_AUTH_RECOVERY_CODES_BASE_COOLDOWN flag')),
                ('multiplier', models.PositiveSmallIntegerField(default=django_auth_recovery_codes.app_settings.default_multiplier, help_text='The multiplier used to increase the wait time .Default value used from the settings.DJANGO_AUTH_RECOVERY_CODES_COOLDOWN_MULTIPLIER flag')),
                ('login_attempts', models.PositiveSmallIntegerField(default=0)),
                ('max_login_attempts', models.PositiveSmallIntegerField(default=django_auth_recovery_codes.app_settings.default_max_login_attempts)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('modified_at', models.DateTimeField(auto_now=True)),
                ('last_login_attempt', models.DateTimeField(auto_now=True)),
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'abstract': False,
            },
        ),
        migrations.CreateModel(
            name='LoginRateLimterAudit',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('modified_at', models.DateTimeField(auto_now=True)),
                ('login_attempts', models.PositiveSmallIntegerField(default=0)),
                ('user', models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'abstract': False,
            },
        ),
        migrations.CreateModel(
            name='RecoveryCodesBatch',
            fields=[
                ('last_attempt', models.DateTimeField(auto_now=True)),
                ('cooldown_seconds', models.PositiveSmallIntegerField(default=django_auth_recovery_codes.app_settings.default_cooldown_seconds, help_text='The number of seconds before a new request can be made. Default valued used from the settings.DJANGO_AUTH_RECOVERY_CODES_BASE_COOLDOWN flag')),
                ('multiplier', models.PositiveSmallIntegerField(default=django_auth_recovery_codes.app_settings.default_multiplier, help_text='The multiplier used to increase the wait time .Default value used from the settings.DJANGO_AUTH_RECOVERY_CODES_COOLDOWN_MULTIPLIER flag')),
                ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)),
                ('number_issued', models.PositiveSmallIntegerField(default=10)),
                ('number_removed', models.PositiveSmallIntegerField(default=0)),
                ('number_invalidated', models.PositiveSmallIntegerField(default=0)),
                ('number_used', models.PositiveSmallIntegerField(default=0)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('modified_at', models.DateTimeField(auto_now=True)),
                ('status', models.CharField(choices=[('a', 'Active'), ('i', 'Invalidate'), ('p', 'Pending Delete'), ('d', 'Deleted')], db_index=True, default='a', max_length=1)),
                ('expiry_date', models.DateField(blank=True, db_index=True, null=True)),
                ('deleted_at', models.DateTimeField(blank=True, null=True)),
                ('viewed', models.BooleanField(default=False)),
                ('downloaded', models.BooleanField(default=False)),
                ('emailed', models.BooleanField(default=False)),
                ('generated', models.BooleanField(default=False)),
                ('automatic_removal', models.BooleanField(default=True)),
                ('requested_attempt', models.PositiveSmallIntegerField(default=0)),
                ('deleted_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
                ('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='recovery_batches', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'RecoveryCodesBatch',
                'verbose_name_plural': 'RecoveryCodeBatches',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='RecoveryCodesBatchHistory',
            fields=[
                ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)),
                ('number_issued', models.PositiveSmallIntegerField(default=10)),
                ('number_removed', models.PositiveSmallIntegerField(default=0)),
                ('number_invalidated', models.PositiveSmallIntegerField(default=0)),
                ('number_used', models.PositiveSmallIntegerField(default=0)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('modified_at', models.DateTimeField(auto_now=True)),
                ('status', models.CharField(choices=[('a', 'Active'), ('i', 'Invalidate'), ('p', 'Pending Delete'), ('d', 'Deleted')], db_index=True, default='a', max_length=1)),
                ('expiry_date', models.DateField(blank=True, db_index=True, null=True)),
                ('deleted_at', models.DateTimeField(blank=True, null=True)),
                ('viewed', models.BooleanField(default=False)),
                ('downloaded', models.BooleanField(default=False)),
                ('emailed', models.BooleanField(default=False)),
                ('generated', models.BooleanField(default=False)),
                ('batch_id', models.UUIDField()),
                ('deleted_by_username', models.CharField(blank=True, max_length=60)),
                ('deleted_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
                ('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='recovery_batches_history', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'verbose_name': 'Recovery Code Batch History',
                'verbose_name_plural': 'Recovery Code Batch Histories',
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='RecoveryCodeSetup',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('verified_at', models.DateTimeField(auto_now_add=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('modified_at', models.DateTimeField(auto_now=True)),
                ('success', models.BooleanField(default=False)),
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='code_setup', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'abstract': False,
            },
        ),
        migrations.CreateModel(
            name='RecoveryCodeAudit',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('action', models.CharField(choices=[('deleted', 'Deleted'), ('invalidated', 'Invalidated'), ('already_deleted', 'Already deleted'), ('already_invalidated', 'Already invalidated'), ('invalid_code', 'Invalid code entered'), ('batch_marked_for_deletion', 'Batch marked for deletion'), ('batch_purged', 'Batch purged (async deletion)')], max_length=50)),
                ('number_deleted', models.PositiveSmallIntegerField(default=0)),
                ('number_issued', models.PositiveSmallIntegerField(default=0)),
                ('reason', models.TextField(blank=True, null=True)),
                ('timestamp', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('deleted_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='performed_recovery_code_actions', to=settings.AUTH_USER_MODEL)),
                ('user_issued_to', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='recovery_code_audits', to=settings.AUTH_USER_MODEL)),
                ('batch', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='audit_logs', to='django_auth_recovery_codes.recoverycodesbatch')),
            ],
            options={
                'ordering': ['-timestamp'],
                'indexes': [models.Index(fields=['-timestamp'], name='recoverycodeaudit_ts_idx'), models.Index(fields=['action'], name='recoverycodeaudit_action_idx'), models.Index(fields=['user_issued_to'], name='recoverycodeaudit_user_idx'), models.Index(fields=['batch'], name='recoverycodeaudit_batch_idx')],
            },
        ),
        migrations.CreateModel(
            name='RecoveryCode',
            fields=[
                ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)),
                ('hash_code', models.CharField(db_index=True, editable=False, max_length=128)),
                ('look_up_hash', models.CharField(blank=True, db_index=True, editable=False, max_length=128, unique=True)),
                ('mark_for_deletion', models.BooleanField(db_index=True, default=False)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('modified_at', models.DateTimeField(auto_now=True)),
                ('status', models.CharField(choices=[('a', 'Active'), ('i', 'Invalidate'), ('p', 'Pending Delete'), ('d', 'Deleted')], db_index=True, default='a', max_length=1)),
                ('automatic_removal', models.BooleanField(default=True)),
                ('days_to_expire', models.PositiveSmallIntegerField(db_index=True, default=0)),
                ('is_used', models.BooleanField(default=False)),
                ('is_deactivated', models.BooleanField(default=False)),
                ('deleted_at', models.DateTimeField(blank=True, null=True)),
                ('deleted_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='recovery_code', to=settings.AUTH_USER_MODEL)),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='recovery_codes', to=settings.AUTH_USER_MODEL)),
                ('batch', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='recovery_codes', to='django_auth_recovery_codes.recoverycodesbatch')),
            ],
            options={
                'indexes': [models.Index(fields=['user', 'look_up_hash'], name='user_lookup_idx')],
                'constraints': [models.UniqueConstraint(fields=('user', 'look_up_hash'), name='unique_user_lookup_hash')],
            },
        ),
    ]
