# Generated by Django 5.2.17 on 2026-10-08 04:46

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


class Migration(migrations.Migration):

    dependencies = [
        ('exams', '0039_backfill_task_category'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='ConfigMetric',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('code', models.CharField(help_text='Stable ID, e.g. POL-TSK-001', max_length=40, unique=True)),
                ('title_ur', models.CharField(max_length=200)),
                ('category', models.CharField(choices=[('ATTENDANCE', 'Attendance'), ('TASK', 'Daily task'), ('BEHAVIOUR', 'Behaviour'), ('CHARACTER', 'Character'), ('HANDWRITING', 'Handwriting'), ('READING', 'Reading'), ('ACADEMIC', 'Academic')], db_index=True, max_length=20)),
                ('kind', models.CharField(choices=[('VIOLATION', 'Violation'), ('CREDIT', 'Credit')], db_index=True, max_length=10)),
                ('severity', models.CharField(choices=[('LOW', 'Low'), ('MEDIUM', 'Medium'), ('HIGH', 'High'), ('CRITICAL', 'Critical')], db_index=True, max_length=10)),
                ('points', models.IntegerField(help_text='Negative for violations, positive for credits.')),
                ('direction', models.CharField(choices=[('BETTER_LOWER', 'Better when lower (e.g. DASH-2)'), ('BETTER_HIGHER', 'Better when higher (e.g. WCPM)'), ('NEUTRAL', 'Neutral (count)')], default='NEUTRAL', max_length=15)),
                ('threshold_expr', models.CharField(blank=True, help_text='Safe grammar: LHS OP RHS (see spec s5).', max_length=200)),
                ('strictness', models.CharField(choices=[('STRICT', 'Strict (fires immediately)'), ('FLEXIBLE', 'Flexible (grace window)'), ('ADVISORY', 'Advisory (no deduction)')], db_index=True, default='STRICT', max_length=10)),
                ('grace_days', models.PositiveSmallIntegerField(default=7, help_text='Grace window for FLEXIBLE strictness (days).')),
                ('standard_cited', models.CharField(help_text='Named standard grounding this metric. Required (AERA 1.0).', max_length=300)),
                ('evidence_range', models.JSONField(blank=True, default=dict, help_text='Permitted value range by the cited standard.')),
                ('override_reason', models.TextField(blank=True, help_text='Required only when threshold falls outside evidence_range.')),
                ('is_active', models.BooleanField(db_index=True, default=True)),
                ('effective_from', models.DateTimeField(blank=True, null=True)),
                ('effective_to', models.DateTimeField(blank=True, null=True)),
                ('version', models.PositiveIntegerField(default=1)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'ordering': ['category', 'code'],
                'indexes': [models.Index(fields=['category', 'is_active'], name='exams_confi_categor_7beb95_idx'), models.Index(fields=['kind', 'is_active'], name='exams_confi_kind_4301f6_idx'), models.Index(fields=['strictness', 'is_active'], name='exams_confi_strictn_6bca20_idx')],
            },
        ),
        migrations.CreateModel(
            name='ConfigChangeProposal',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('reason', models.TextField(help_text='Required; one-line why the change is being proposed.')),
                ('before_snapshot', models.JSONField(default=dict, help_text='Catalogue state before the change.')),
                ('after_snapshot', models.JSONField(default=dict, help_text='Catalogue state after the change.')),
                ('maker_2fa_id', models.CharField(blank=True, help_text='TOTP challenge ID that authorised the proposal.', max_length=64)),
                ('status', models.CharField(choices=[('PENDING', 'Pending approval'), ('APPROVED', 'Approved (cooling off)'), ('APPLIED', 'Applied'), ('REJECTED', 'Rejected'), ('EXPIRED', 'Expired')], db_index=True, default='PENDING', max_length=12)),
                ('approved_at', models.DateTimeField(blank=True, null=True)),
                ('approver_2fa_id', models.CharField(blank=True, max_length=64)),
                ('applied_at', models.DateTimeField(blank=True, null=True)),
                ('applied_version', models.PositiveIntegerField(blank=True, null=True)),
                ('rejection_reason', models.TextField(blank=True)),
                ('expires_at', models.DateTimeField(blank=True, db_index=True, null=True)),
                ('approver', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='config_proposals_approved', to=settings.AUTH_USER_MODEL)),
                ('maker', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='config_proposals_made', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['status', '-created_at'], name='exams_confi_status_6d426c_idx'), models.Index(fields=['maker', 'status'], name='exams_confi_maker_i_929788_idx')],
            },
        ),
        migrations.CreateModel(
            name='ConfigSnapshot',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('version', models.PositiveIntegerField(db_index=True, unique=True)),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('payload_json', models.JSONField(default=dict, help_text='Full catalogue of ConfigMetric rows as a JSON dict.')),
                ('sha256', models.CharField(db_index=True, max_length=64)),
                ('prev_version', models.PositiveIntegerField(blank=True, null=True)),
                ('is_current', models.BooleanField(db_index=True, default=False)),
                ('note', models.TextField(blank=True, help_text='One-line description of what changed in this snapshot.')),
                ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='config_snapshots_created', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['-version'],
                'indexes': [models.Index(fields=['is_current'], name='exams_confi_is_curr_587ed1_idx'), models.Index(fields=['version'], name='exams_confi_version_ae2b63_idx')],
            },
        ),
        migrations.CreateModel(
            name='TwoFactorChallenge',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('purpose', models.CharField(help_text='E.g. admin_config_change, admin_console_login.', max_length=40)),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('expires_at', models.DateTimeField(db_index=True)),
                ('consumed_at', models.DateTimeField(blank=True, null=True)),
                ('result', models.CharField(choices=[('PASS', 'Pass'), ('FAIL', 'Fail'), ('EXPIRED', 'Expired')], db_index=True, default='EXPIRED', max_length=10)),
                ('ip_address', models.GenericIPAddressField(blank=True, null=True)),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='mfa_challenges', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['user', '-created_at'], name='exams_twofa_user_id_d6420d_idx'), models.Index(fields=['result', '-created_at'], name='exams_twofa_result_0012a3_idx')],
            },
        ),
        migrations.CreateModel(
            name='UserMFA',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('secret_b32', models.CharField(help_text='Base32-encoded TOTP shared secret. Never displayed after enrolment.', max_length=64)),
                ('enrolled_at', models.DateTimeField(auto_now_add=True)),
                ('last_used_at', models.DateTimeField(blank=True, null=True)),
                ('recovery_hashes', models.JSONField(blank=True, default=list, help_text='List of SHA-256 hashes of single-use recovery codes.')),
                ('is_active', models.BooleanField(db_index=True, default=True)),
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='mfa', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'indexes': [models.Index(fields=['is_active'], name='exams_userm_is_acti_8f64a7_idx')],
            },
        ),
    ]
