# Generated by Django 5.2.1 on 2026-07-23 06:57

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('courses', '0003_add_meeting_fields_to_lesson'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='CertificationApplication',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('status', models.CharField(choices=[('pending_payment', 'Pending payment'), ('paid', 'Paid — ready for exam'), ('in_exam', 'Exam in progress'), ('passed', 'Passed'), ('failed', 'Failed'), ('certified', 'Certificate issued')], default='pending_payment', max_length=30)),
                ('payment_method', models.CharField(blank=True, default='', max_length=20)),
                ('payment_proof', models.ImageField(blank=True, null=True, upload_to='cert_payment_proofs/')),
                ('payment_note', models.TextField(blank=True)),
                ('stripe_session_id', models.CharField(blank=True, max_length=255)),
                ('stripe_payment_intent', models.CharField(blank=True, max_length=255)),
                ('paid_at', models.DateTimeField(blank=True, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('approved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='approved_cert_applications', to=settings.AUTH_USER_MODEL)),
                ('candidate', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='certification_applications', to=settings.AUTH_USER_MODEL)),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.CreateModel(
            name='Certificate',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('verification_code', models.CharField(db_index=True, max_length=32, unique=True)),
                ('recipient_name', models.CharField(max_length=200)),
                ('program_title', models.CharField(max_length=200)),
                ('score_percent', models.DecimalField(decimal_places=2, max_digits=5)),
                ('issued_at', models.DateTimeField(auto_now_add=True)),
                ('is_revoked', models.BooleanField(default=False)),
                ('revoke_reason', models.CharField(blank=True, max_length=255)),
                ('application', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='certificate', to='certifications.certificationapplication')),
            ],
            options={
                'ordering': ['-issued_at'],
            },
        ),
        migrations.CreateModel(
            name='CertificationProgram',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('title', models.CharField(max_length=200)),
                ('slug', models.SlugField(blank=True, max_length=220, unique=True)),
                ('short_description', models.CharField(max_length=300)),
                ('full_description', models.TextField(blank=True)),
                ('thumbnail', models.ImageField(blank=True, null=True, upload_to='certification_thumbnails/')),
                ('fee', models.DecimalField(decimal_places=2, default=0, max_digits=8)),
                ('questions_per_exam', models.PositiveIntegerField(default=100, help_text='How many MCQs are drawn for each exam attempt (typically 100).')),
                ('passing_score', models.PositiveIntegerField(default=70, help_text='Minimum percentage required to pass.')),
                ('time_limit_minutes', models.PositiveIntegerField(default=120, help_text='Exam duration in minutes. 0 = no limit.')),
                ('max_attempts', models.PositiveIntegerField(default=3, help_text='Max exam attempts after payment. 0 = unlimited.')),
                ('is_published', models.BooleanField(default=False)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('related_course', models.ForeignKey(blank=True, help_text='Optional link to a course this cert maps to.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='certification_programs', to='courses.course')),
            ],
            options={
                'ordering': ['-created_at'],
            },
        ),
        migrations.AddField(
            model_name='certificationapplication',
            name='program',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='applications', to='certifications.certificationprogram'),
        ),
        migrations.CreateModel(
            name='ExamAttempt',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('started_at', models.DateTimeField(auto_now_add=True)),
                ('submitted_at', models.DateTimeField(blank=True, null=True)),
                ('question_ids', models.JSONField(blank=True, default=list)),
                ('score_percent', models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True)),
                ('correct_count', models.PositiveIntegerField(default=0)),
                ('total_asked', models.PositiveIntegerField(default=0)),
                ('passed', models.BooleanField(default=False)),
                ('application', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attempts', to='certifications.certificationapplication')),
            ],
            options={
                'ordering': ['-started_at'],
            },
        ),
        migrations.CreateModel(
            name='ExamQuestion',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('text', models.TextField()),
                ('order', models.PositiveIntegerField(default=0)),
                ('is_active', models.BooleanField(default=True)),
                ('program', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='questions', to='certifications.certificationprogram')),
            ],
            options={
                'ordering': ['order', 'id'],
            },
        ),
        migrations.CreateModel(
            name='ExamChoice',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('text', models.CharField(max_length=500)),
                ('is_correct', models.BooleanField(default=False)),
                ('question', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='choices', to='certifications.examquestion')),
            ],
        ),
        migrations.AlterUniqueTogether(
            name='certificationapplication',
            unique_together={('candidate', 'program')},
        ),
        migrations.CreateModel(
            name='ExamAnswer',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('is_correct', models.BooleanField(default=False)),
                ('attempt', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='answers', to='certifications.examattempt')),
                ('selected_choice', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='certifications.examchoice')),
                ('question', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='certifications.examquestion')),
            ],
            options={
                'unique_together': {('attempt', 'question')},
            },
        ),
    ]
