# Generated by Django 6.0.3 on 2026-03-30 17:43

import django.core.validators
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('academics', '0002_subject_book_document'),
        ('people', '0001_initial'),
    ]

    operations = [
        migrations.CreateModel(
            name='ExamGradeSystem',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=100)),
                ('description', models.TextField(blank=True)),
                ('grade_ranges', models.JSONField(help_text="JSON field storing grade ranges e.g., {'A+': [90,100], 'A': [80,89]}")),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
            ],
        ),
        migrations.CreateModel(
            name='Exam',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=200)),
                ('code', models.CharField(max_length=50, unique=True)),
                ('start_date', models.DateField()),
                ('end_date', models.DateField()),
                ('weightage', models.DecimalField(decimal_places=2, default=100.0, max_digits=5, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(100)])),
                ('status', models.CharField(choices=[('scheduled', 'Scheduled'), ('ongoing', 'Ongoing'), ('completed', 'Completed'), ('cancelled', 'Cancelled'), ('results_published', 'Results Published')], default='scheduled', max_length=20)),
                ('results_published_date', models.DateTimeField(blank=True, null=True)),
                ('instructions', models.TextField(blank=True)),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('academic_class', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='exams', to='academics.academicclass')),
                ('academic_year', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='exams', to='academics.academicyear')),
            ],
            options={
                'ordering': ['-start_date'],
            },
        ),
        migrations.CreateModel(
            name='ExamClassRegistration',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('registration_date', models.DateTimeField(auto_now_add=True)),
                ('hall_ticket_prefix', models.CharField(blank=True, max_length=20)),
                ('seat_number_prefix', models.CharField(blank=True, max_length=20)),
                ('is_registered', models.BooleanField(default=True)),
                ('auto_generate_hall_tickets', models.BooleanField(default=True)),
                ('auto_generate_seat_numbers', models.BooleanField(default=False)),
                ('notes', models.TextField(blank=True)),
                ('academic_class', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='exam_class_registrations', to='academics.academicclass')),
                ('exam', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='class_registrations', to='exam.exam')),
                ('registered_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='registered_exams', to='people.teacher')),
            ],
            options={
                'unique_together': {('exam', 'academic_class')},
            },
        ),
        migrations.CreateModel(
            name='ExamSubject',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('max_marks', models.PositiveIntegerField(default=100)),
                ('passing_marks', models.PositiveIntegerField(default=35)),
                ('exam_date', models.DateField()),
                ('start_time', models.TimeField()),
                ('duration_minutes', models.PositiveIntegerField(default=180, help_text='Duration in minutes')),
                ('room_number', models.CharField(blank=True, max_length=50)),
                ('extra_instructions', models.TextField(blank=True)),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('exam', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='exam_subjects', to='exam.exam')),
                ('invigilators', models.ManyToManyField(blank=True, related_name='invigilated_exams', to='people.teacher')),
                ('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='exam_subjects', to='academics.subject')),
                ('teacher_in_charge', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='exam_subjects_charged', to='people.teacher')),
            ],
            options={
                'ordering': ['exam_date', 'start_time'],
                'unique_together': {('exam', 'subject')},
            },
        ),
        migrations.CreateModel(
            name='ExamType',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=100)),
                ('code', models.CharField(max_length=20, unique=True)),
                ('is_terminal', models.BooleanField(default=False, help_text='Whether this is a terminal exam (like final exam)')),
                ('is_mid_term', models.BooleanField(default=False, help_text='Whether this is a mid-term exam')),
                ('is_continuous_assessment', models.BooleanField(default=False, help_text='Whether this is part of continuous assessment')),
                ('default_weightage', models.DecimalField(decimal_places=2, default=100.0, max_digits=5, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(100)])),
                ('grading_system', models.CharField(choices=[('marks', 'Marks Based'), ('grade', 'Grade Based'), ('cgpa', 'CGPA Based')], default='marks', max_length=20)),
                ('max_marks', models.PositiveIntegerField(default=100)),
                ('passing_marks', models.PositiveIntegerField(default=35)),
                ('is_active', models.BooleanField(default=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('academic_term', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='exam_types', to='academics.academicterm')),
            ],
            options={
                'ordering': ['name'],
            },
        ),
        migrations.AddField(
            model_name='exam',
            name='exam_type',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='exams', to='exam.examtype'),
        ),
        migrations.CreateModel(
            name='ExamConfiguration',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('promotion_min_percentage', models.DecimalField(decimal_places=2, default=35.0, help_text='Minimum percentage required for promotion', max_digits=5)),
                ('max_subjects_fail_allowed', models.PositiveIntegerField(default=2, help_text='Maximum number of subjects a student can fail and still be promoted')),
                ('allow_mark_entry_before_exam', models.BooleanField(default=False)),
                ('allow_mark_entry_after_results_published', models.BooleanField(default=False)),
                ('enable_grade_points', models.BooleanField(default=True)),
                ('enable_rank_calculation', models.BooleanField(default=True)),
                ('auto_register_students_on_exam_creation', models.BooleanField(default=True, help_text='Automatically register all students when exam is created')),
                ('allow_student_self_registration', models.BooleanField(default=False)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('academic_year', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='exam_configurations', to='academics.academicyear')),
                ('default_grade_system', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='configurations', to='exam.examgradesystem')),
            ],
            options={
                'unique_together': {('academic_year',)},
            },
        ),
        migrations.CreateModel(
            name='ExamResult',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('total_marks', models.DecimalField(blank=True, decimal_places=2, max_digits=8, null=True)),
                ('total_max_marks', models.DecimalField(blank=True, decimal_places=2, max_digits=8, null=True)),
                ('percentage', models.DecimalField(blank=True, decimal_places=2, max_digits=5, null=True)),
                ('overall_grade', models.CharField(blank=True, max_length=10)),
                ('overall_grade_point', models.DecimalField(blank=True, decimal_places=2, max_digits=4, null=True)),
                ('result_status', models.CharField(choices=[('pass', 'Pass'), ('fail', 'Fail'), ('absent', 'Absent'), ('withheld', 'Withheld'), ('promoted', 'Promoted'), ('detained', 'Detained')], default='pass', max_length=20)),
                ('rank', models.PositiveIntegerField(blank=True, null=True)),
                ('remarks', models.TextField(blank=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('exam', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='student_results', to='exam.exam')),
                ('student_enrollment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='exam_results', to='academics.studentenrollment')),
            ],
            options={
                'unique_together': {('student_enrollment', 'exam')},
            },
        ),
        migrations.CreateModel(
            name='ExamAttendance',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('is_present', models.BooleanField(default=True)),
                ('arrival_time', models.TimeField(blank=True, null=True)),
                ('departure_time', models.TimeField(blank=True, null=True)),
                ('is_late', models.BooleanField(default=False)),
                ('late_minutes', models.PositiveIntegerField(default=0)),
                ('early_departure_minutes', models.PositiveIntegerField(default=0)),
                ('remarks', models.TextField(blank=True)),
                ('marked_at', models.DateTimeField(auto_now_add=True)),
                ('marked_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='marked_attendance', to='people.teacher')),
                ('student_enrollment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='exam_attendance', to='academics.studentenrollment')),
                ('exam_subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attendance', to='exam.examsubject')),
            ],
            options={
                'unique_together': {('student_enrollment', 'exam_subject')},
            },
        ),
        migrations.AlterUniqueTogether(
            name='exam',
            unique_together={('academic_year', 'academic_class', 'name')},
        ),
        migrations.CreateModel(
            name='StudentExamRegistration',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('registration_date', models.DateTimeField(auto_now_add=True)),
                ('registration_type', models.CharField(choices=[('individual', 'Individual Registration'), ('class_based', 'Class Based Registration'), ('bulk_upload', 'Bulk Upload Registration')], default='individual', max_length=20)),
                ('is_registered', models.BooleanField(default=True)),
                ('hall_ticket_number', models.CharField(blank=True, max_length=50)),
                ('seat_number', models.CharField(blank=True, max_length=50)),
                ('needs_special_accommodation', models.BooleanField(default=False)),
                ('accommodation_details', models.TextField(blank=True)),
                ('notes', models.TextField(blank=True)),
                ('class_registration', models.ForeignKey(blank=True, help_text='If this registration came from class-wise registration', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='student_registrations', to='exam.examclassregistration')),
                ('exam', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='student_registrations', to='exam.exam')),
                ('registered_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='registered_students', to='people.teacher')),
                ('student_enrollment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='exam_registrations', to='academics.studentenrollment')),
            ],
            options={
                'unique_together': {('student_enrollment', 'exam')},
            },
        ),
        migrations.CreateModel(
            name='StudentMarks',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('obtained_marks', models.DecimalField(blank=True, decimal_places=2, max_digits=6, null=True, validators=[django.core.validators.MinValueValidator(0)])),
                ('grade', models.CharField(blank=True, max_length=10)),
                ('grade_point', models.DecimalField(blank=True, decimal_places=2, max_digits=4, null=True, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(10)])),
                ('is_absent', models.BooleanField(default=False)),
                ('is_withheld', models.BooleanField(default=False, help_text='Whether marks are withheld due to disciplinary reasons')),
                ('is_revaluation_applied', models.BooleanField(default=False)),
                ('entry_date', models.DateTimeField(auto_now_add=True)),
                ('last_updated', models.DateTimeField(auto_now=True)),
                ('revaluation_marks', models.DecimalField(blank=True, decimal_places=2, max_digits=6, null=True)),
                ('revaluation_reason', models.TextField(blank=True)),
                ('revaluation_date', models.DateTimeField(blank=True, null=True)),
                ('remarks', models.TextField(blank=True)),
                ('entered_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='entered_marks', to='people.teacher')),
                ('exam_subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='student_marks', to='exam.examsubject')),
                ('student_enrollment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='exam_marks', to='academics.studentenrollment')),
            ],
            options={
                'unique_together': {('student_enrollment', 'exam_subject')},
            },
        ),
    ]
