# Generated by Django 5.2.17 on 2026-10-07 20:08

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


class Migration(migrations.Migration):

    dependencies = [
        ('exams', '0034_feature_access_killswitch'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Badge',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('code', models.CharField(help_text='E.g. HW-HERO, BOOK-FIN, IRON-STREAK.', max_length=60, unique=True)),
                ('title_ur', models.CharField(max_length=120)),
                ('description_ur', models.CharField(blank=True, max_length=200)),
                ('tier', models.PositiveSmallIntegerField(choices=[(1, 'Tier 1 - Micro'), (2, 'Tier 2 - Weekly'), (3, 'Tier 3 - Skill'), (4, 'Tier 4 - Milestone')], db_index=True, default=1)),
                ('trigger', models.JSONField(blank=True, default=dict, help_text='Machine-checkable criteria (e.g. {event: TASK_ON_TIME, count: 7}).')),
                ('health_points', models.PositiveSmallIntegerField(default=0, help_text='Health points awarded when badge earned.')),
                ('icon_svg', models.TextField(blank=True, help_text='Inline SVG (WCAG 2.2 AA contrast).')),
                ('is_active', models.BooleanField(db_index=True, default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
            ],
            options={
                'ordering': ['tier', 'code'],
            },
        ),
        migrations.CreateModel(
            name='HealthPolicy',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('code', models.CharField(help_text='Policy ID, e.g. POL-TSK-001 or CR-HW-IMP-2', max_length=40, unique=True)),
                ('kind', models.CharField(choices=[('VIOLATION', 'Violation'), ('CREDIT', 'Credit')], db_index=True, max_length=10)),
                ('category', models.CharField(choices=[('ATTENDANCE', 'Attendance'), ('TASK', 'Daily task'), ('BEHAVIOUR', 'Behaviour'), ('CHARACTER', 'Character'), ('HANDWRITING', 'Handwriting'), ('READING', 'Reading'), ('ACADEMIC', 'Academic performance')], db_index=True, max_length=20)),
                ('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.')),
                ('title_ur', models.CharField(help_text='Roman Urdu short title shown to student/parent.', max_length=200)),
                ('description_ur', models.TextField(blank=True, help_text='Roman Urdu description of the policy.')),
                ('standard_cited', models.CharField(blank=True, help_text='Named standard that grounds this policy.', max_length=300)),
                ('is_active', models.BooleanField(db_index=True, default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
            ],
            options={
                'ordering': ['code'],
                'indexes': [models.Index(fields=['kind', 'is_active'], name='exams_healt_kind_1caa52_idx'), models.Index(fields=['category', 'is_active'], name='exams_healt_categor_459ccb_idx')],
            },
        ),
        migrations.CreateModel(
            name='HealthEvent',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('kind', models.CharField(choices=[('VIOLATION', 'Violation'), ('CREDIT', 'Credit')], db_index=True, max_length=10)),
                ('points', models.IntegerField(help_text='Snapshot of policy.points at event time.')),
                ('reason', models.TextField(help_text='Roman Urdu, plain language.')),
                ('evidence', models.JSONField(blank=True, default=dict)),
                ('source', models.CharField(choices=[('AUTO', 'Automatic (Algorithm)'), ('TEACHER', 'Teacher'), ('PARENT', 'Parent'), ('STUDENT', 'Student'), ('SYSTEM', 'System')], db_index=True, default='AUTO', max_length=10)),
                ('overridden_at', models.DateTimeField(blank=True, null=True)),
                ('override_reason', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('actor', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='health_events_authored', to=settings.AUTH_USER_MODEL)),
                ('overridden_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='health_events_overridden', to=settings.AUTH_USER_MODEL)),
                ('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='health_events', to='exams.student')),
                ('policy', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='events', to='exams.healthpolicy')),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='HealthScore',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('score', models.IntegerField(db_index=True, default=500)),
                ('band', models.CharField(choices=[('HEALTHY', 'Healthy (700-1000)'), ('WATCH', 'Watch (400-699)'), ('AT_RISK', 'At Risk (200-399)'), ('CRITICAL', 'Critical (0-199)')], db_index=True, default='WATCH', max_length=10)),
                ('event_count', models.PositiveIntegerField(default=0)),
                ('last_event_at', models.DateTimeField(blank=True, null=True)),
                ('last_recompute_at', models.DateTimeField(auto_now=True)),
                ('green_shield_since', models.DateTimeField(blank=True, null=True)),
                ('red_flag_since', models.DateTimeField(blank=True, null=True)),
                ('student', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='health_score', to='exams.student')),
            ],
        ),
        migrations.CreateModel(
            name='Quest',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('status', models.CharField(choices=[('ACTIVE', 'Active'), ('COMPLETED', 'Completed'), ('ABANDONED', 'Abandoned (student exited)'), ('RESET', 'Reset by teacher')], db_index=True, default='ACTIVE', max_length=10)),
                ('total_steps', models.PositiveSmallIntegerField(default=4)),
                ('started_at', models.DateTimeField(auto_now_add=True)),
                ('completed_at', models.DateTimeField(blank=True, null=True)),
                ('last_activity_at', models.DateTimeField(auto_now=True, db_index=True)),
                ('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='quests', to='exams.student')),
                ('student_task', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='quest', to='exams.studenttask')),
            ],
            options={
                'ordering': ['-last_activity_at'],
            },
        ),
        migrations.CreateModel(
            name='QuestStep',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('step_index', models.PositiveSmallIntegerField()),
                ('title_ur', models.CharField(max_length=200)),
                ('instruction_ur', models.CharField(blank=True, max_length=400)),
                ('input_type', models.CharField(default='BUTTON', help_text='BUTTON | PASTE | TEXT | PHOTO | CONFIRM.', max_length=20)),
                ('done_condition', models.JSONField(blank=True, default=dict, help_text='Machine-checkable completion criteria.')),
                ('completed', models.BooleanField(db_index=True, default=False)),
                ('completed_at', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('completed_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='quest_steps_completed', to=settings.AUTH_USER_MODEL)),
                ('quest', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='steps', to='exams.quest')),
            ],
            options={
                'ordering': ['quest', 'step_index'],
            },
        ),
        migrations.CreateModel(
            name='Reinstatement',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('status', models.CharField(choices=[('DRAFT', 'Draft (student filling)'), ('SUBMITTED', 'Submitted for review'), ('APPROVED', 'Approved by teacher'), ('MODIFIED', 'Approved with modifications'), ('REJECTED', 'Rejected by teacher'), ('IN_PROGRESS', 'Recovery contract running'), ('CLEARED', 'Cleared — reinstated'), ('FAILED', 'Failed — escalated')], db_index=True, default='DRAFT', max_length=15)),
                ('trigger_reason', models.TextField(help_text='What caused the suspension (Roman Urdu).')),
                ('trigger_health_score', models.IntegerField(help_text='Score at trigger time (0-1000).')),
                ('parent_apology_ur', models.CharField(blank=True, help_text='Parent apology, Roman Urdu, max 300 chars.', max_length=300)),
                ('parent_name', models.CharField(blank=True, max_length=200)),
                ('parent_confirmed_at', models.DateTimeField(blank=True, null=True)),
                ('root_cause_ur', models.TextField(blank=True)),
                ('corrective_actions', models.JSONField(blank=True, default=list, help_text='List of 3 corrective steps.')),
                ('preventive_measures', models.JSONField(blank=True, default=list, help_text='List of 3 preventive steps.')),
                ('reviewed_at', models.DateTimeField(blank=True, null=True)),
                ('review_notes', models.TextField(blank=True)),
                ('contract_starts_at', models.DateTimeField(blank=True, null=True)),
                ('contract_ends_at', models.DateTimeField(blank=True, null=True)),
                ('contract_extension_count', models.PositiveSmallIntegerField(default=0)),
                ('deposit_kind', models.CharField(blank=True, help_text='PEER_TUTORING_HOURS | EXTRA_PRACTICE_SETS. Never money.', max_length=40)),
                ('deposit_amount', models.PositiveSmallIntegerField(default=0)),
                ('deposit_released_at', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('reviewed_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='reinstatements_reviewed', to=settings.AUTH_USER_MODEL)),
                ('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='reinstatements', to='exams.student')),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='BadgeAward',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('trigger_data', models.JSONField(blank=True, default=dict, help_text='Evidence that fired the trigger.')),
                ('awarded_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('credential_id', models.CharField(blank=True, db_index=True, max_length=64)),
                ('awarded_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='badges_awarded', to=settings.AUTH_USER_MODEL)),
                ('badge', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='awards', to='exams.badge')),
                ('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='badges', to='exams.student')),
            ],
            options={
                'ordering': ['-awarded_at'],
                'indexes': [models.Index(fields=['student', '-awarded_at'], name='exams_badge_student_9c4fd6_idx'), models.Index(fields=['badge', '-awarded_at'], name='exams_badge_badge_i_2f2242_idx')],
            },
        ),
        migrations.CreateModel(
            name='CreditEvent',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('code', models.CharField(help_text='E.g. TASK_ON_TIME, HW_IMPROVEMENT, BOOK_FINISHED.', max_length=60)),
                ('points', models.IntegerField()),
                ('reason', models.TextField(blank=True)),
                ('evidence', models.JSONField(blank=True, default=dict)),
                ('source', models.CharField(db_index=True, default='AUTO', max_length=10)),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('actor', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='credit_events_authored', to=settings.AUTH_USER_MODEL)),
                ('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='credit_events', to='exams.student')),
                ('health_event', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='credits', to='exams.healthevent')),
            ],
            options={
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['student', '-created_at'], name='exams_credi_student_a29e17_idx'), models.Index(fields=['code', '-created_at'], name='exams_credi_code_21a230_idx')],
            },
        ),
        migrations.CreateModel(
            name='BehaviourIncident',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('severity', models.CharField(choices=[('LOW', 'Low'), ('MEDIUM', 'Medium'), ('HIGH', 'High'), ('CRITICAL', 'Critical')], db_index=True, max_length=10)),
                ('category', models.CharField(help_text='E.g. RESPECT_TEACHER, RESPECT_PEER, HONESTY.', max_length=40)),
                ('observed', models.TextField(help_text='Concrete event. What was seen or heard.')),
                ('context', models.TextField(blank=True, help_text='Where / when / with whom.')),
                ('source_label', models.CharField(help_text='Named source (teacher, staff, peer). Anonymous not allowed.', max_length=80)),
                ('student_response', models.TextField(blank=True, help_text="Student's side (due process, Goss v. Lopez).")),
                ('student_responded_at', models.DateTimeField(blank=True, null=True)),
                ('teacher_review', models.TextField(blank=True)),
                ('teacher_reviewed_at', models.DateTimeField(blank=True, null=True)),
                ('status', models.CharField(choices=[('OPEN', 'Open'), ('STUDENT_RESPONDED', 'Student responded'), ('REVIEWED', 'Reviewed by teacher'), ('CLOSED', 'Closed'), ('APPEALED', 'Appealed')], db_index=True, default='OPEN', max_length=20)),
                ('parent_notified_at', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='behaviour_incidents', to='exams.student')),
                ('teacher_reviewed_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='behaviour_incidents_reviewed', to=settings.AUTH_USER_MODEL)),
                ('health_event', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='behaviour_incidents', to='exams.healthevent')),
            ],
            options={
                'ordering': ['-created_at'],
                'indexes': [models.Index(fields=['student', '-created_at'], name='exams_behav_student_06b193_idx'), models.Index(fields=['severity', 'status'], name='exams_behav_severit_ced7c5_idx')],
            },
        ),
        migrations.AddIndex(
            model_name='healthevent',
            index=models.Index(fields=['student', '-created_at'], name='exams_healt_student_3a496f_idx'),
        ),
        migrations.AddIndex(
            model_name='healthevent',
            index=models.Index(fields=['kind', '-created_at'], name='exams_healt_kind_1f2b2f_idx'),
        ),
        migrations.AddIndex(
            model_name='healthscore',
            index=models.Index(fields=['band', '-score'], name='exams_healt_band_a0eadc_idx'),
        ),
        migrations.AddIndex(
            model_name='quest',
            index=models.Index(fields=['student', 'status'], name='exams_quest_student_8fbe3e_idx'),
        ),
        migrations.AddIndex(
            model_name='queststep',
            index=models.Index(fields=['quest', 'completed'], name='exams_quest_quest_i_da4749_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='queststep',
            unique_together={('quest', 'step_index')},
        ),
        migrations.AddIndex(
            model_name='reinstatement',
            index=models.Index(fields=['student', 'status'], name='exams_reins_student_c90a32_idx'),
        ),
        migrations.AddIndex(
            model_name='reinstatement',
            index=models.Index(fields=['status', '-created_at'], name='exams_reins_status_1d31f9_idx'),
        ),
    ]
