# Generated by Django 6.0.3 on 2026-03-15 08:13

import django.core.validators
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('academics', '0001_initial'),
        ('people', '0001_initial'),
    ]

    operations = [
        migrations.CreateModel(
            name='AttendanceLeave',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('leave_type', models.CharField(choices=[('MEDICAL', 'Medical'), ('FAMILY', 'Family'), ('EMERGENCY', 'Emergency'), ('SPORTS', 'Sports / Event'), ('OTHER', 'Other')], max_length=20)),
                ('from_date', models.DateField()),
                ('to_date', models.DateField()),
                ('reason', models.TextField()),
                ('document', models.FileField(blank=True, help_text='Medical certificate or supporting document', null=True, upload_to='attendance/leave_docs/')),
                ('status', models.CharField(choices=[('PENDING', 'Pending'), ('APPROVED', 'Approved'), ('REJECTED', 'Rejected')], default='PENDING', max_length=20)),
                ('approved_at', models.DateTimeField(blank=True, null=True)),
                ('rejection_reason', 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)),
                ('approved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='leaves_approved', to='people.teacher')),
                ('enrollment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='leaves', to='academics.studentenrollment')),
                ('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='leaves', to='people.student')),
            ],
            options={
                'ordering': ['-from_date'],
            },
        ),
        migrations.CreateModel(
            name='AttendanceSession',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('date', models.DateField()),
                ('period_number', models.PositiveSmallIntegerField(blank=True, help_text='Timetable period number; null for full-day sessions', null=True)),
                ('session_type', models.CharField(choices=[('MORNING', 'Morning'), ('AFTERNOON', 'Afternoon'), ('PERIOD', 'Period'), ('FULL_DAY', 'Full Day')], default='FULL_DAY', max_length=20)),
                ('start_time', models.TimeField(blank=True, null=True)),
                ('end_time', models.TimeField(blank=True, null=True)),
                ('status', models.CharField(choices=[('OPEN', 'Open'), ('SUBMITTED', 'Submitted'), ('LOCKED', 'Locked')], default='OPEN', max_length=20)),
                ('total_students', models.PositiveIntegerField(default=0)),
                ('present_count', models.PositiveIntegerField(default=0)),
                ('absent_count', models.PositiveIntegerField(default=0)),
                ('late_count', models.PositiveIntegerField(default=0)),
                ('leave_count', models.PositiveIntegerField(default=0)),
                ('remarks', 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='attendance_sessions', to='academics.academicclass')),
                ('subject', models.ForeignKey(blank=True, help_text='Populated only for period-level attendance', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='attendance_sessions', to='academics.subject')),
                ('taken_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='attendance_sessions_taken', to='people.teacher')),
            ],
            options={
                'ordering': ['-date', 'period_number'],
            },
        ),
        migrations.CreateModel(
            name='AttendanceSummary',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('month', models.PositiveSmallIntegerField(validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(12)])),
                ('year', models.PositiveSmallIntegerField()),
                ('total_working_days', models.PositiveSmallIntegerField(default=0)),
                ('present_days', models.PositiveSmallIntegerField(default=0)),
                ('absent_days', models.PositiveSmallIntegerField(default=0)),
                ('late_days', models.PositiveSmallIntegerField(default=0)),
                ('leave_days', models.PositiveSmallIntegerField(default=0)),
                ('half_days', models.PositiveSmallIntegerField(default=0)),
                ('attendance_percentage', models.DecimalField(decimal_places=2, default=0.0, max_digits=5)),
                ('is_below_minimum', models.BooleanField(default=False)),
                ('last_computed_at', models.DateTimeField(auto_now=True)),
                ('academic_class', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attendance_summaries', to='academics.academicclass')),
                ('enrollment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attendance_summaries', to='academics.studentenrollment')),
                ('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attendance_summaries', to='people.student')),
            ],
            options={
                'ordering': ['-year', '-month'],
            },
        ),
        migrations.CreateModel(
            name='StudentAttendance',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('status', models.CharField(choices=[('PRESENT', 'Present'), ('ABSENT', 'Absent'), ('LATE', 'Late'), ('LEAVE', 'On Approved Leave'), ('HALF_DAY', 'Half Day'), ('HOLIDAY', 'Holiday / School Closed')], max_length=20)),
                ('remarks', models.CharField(blank=True, max_length=255)),
                ('late_minutes', models.PositiveSmallIntegerField(blank=True, help_text='Minutes late; only relevant when status=LATE', null=True)),
                ('marked_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('is_active', models.BooleanField(default=True)),
                ('enrollment', models.ForeignKey(help_text="Ties attendance to the student's class and academic year", on_delete=django.db.models.deletion.CASCADE, related_name='attendances', to='academics.studentenrollment')),
                ('leave', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='attendance_records', to='attendance.attendanceleave')),
                ('marked_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='attendances_marked', to='people.teacher')),
                ('session', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='student_attendances', to='attendance.attendancesession')),
                ('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attendances', to='people.student')),
            ],
            options={
                'ordering': ['session__date', 'enrollment__roll_number'],
            },
        ),
        migrations.AddIndex(
            model_name='attendanceleave',
            index=models.Index(fields=['student', 'from_date'], name='attendance__student_82d0b6_idx'),
        ),
        migrations.AddIndex(
            model_name='attendanceleave',
            index=models.Index(fields=['status'], name='attendance__status_c14481_idx'),
        ),
        migrations.AddIndex(
            model_name='attendanceleave',
            index=models.Index(fields=['enrollment', 'from_date', 'to_date'], name='attendance__enrollm_bc81e7_idx'),
        ),
        migrations.AddIndex(
            model_name='attendancesession',
            index=models.Index(fields=['date', 'academic_class'], name='attendance__date_bf0803_idx'),
        ),
        migrations.AddIndex(
            model_name='attendancesession',
            index=models.Index(fields=['taken_by', 'date'], name='attendance__taken_b_f12277_idx'),
        ),
        migrations.AddIndex(
            model_name='attendancesession',
            index=models.Index(fields=['status'], name='attendance__status_a3ed5f_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='attendancesession',
            unique_together={('academic_class', 'date', 'period_number', 'session_type')},
        ),
        migrations.AddIndex(
            model_name='attendancesummary',
            index=models.Index(fields=['student', 'year', 'month'], name='attendance__student_a5697d_idx'),
        ),
        migrations.AddIndex(
            model_name='attendancesummary',
            index=models.Index(fields=['academic_class', 'year', 'month'], name='attendance__academi_80e4f8_idx'),
        ),
        migrations.AddIndex(
            model_name='attendancesummary',
            index=models.Index(fields=['is_below_minimum'], name='attendance__is_belo_c2222f_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='attendancesummary',
            unique_together={('enrollment', 'month', 'year')},
        ),
        migrations.AddIndex(
            model_name='studentattendance',
            index=models.Index(fields=['student', 'session'], name='attendance__student_e8308b_idx'),
        ),
        migrations.AddIndex(
            model_name='studentattendance',
            index=models.Index(fields=['enrollment', 'status'], name='attendance__enrollm_a2a5f9_idx'),
        ),
        migrations.AddIndex(
            model_name='studentattendance',
            index=models.Index(fields=['status'], name='attendance__status_938ff8_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='studentattendance',
            unique_together={('session', 'enrollment')},
        ),
    ]
