# Generated by Django 6.0.4 on 2026-05-03 11:30

import django.db.models.deletion
import uuid
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='ChatParticipantParent',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('role', models.CharField(choices=[('MEMBER', 'Member'), ('MODERATOR', 'Moderator'), ('ADMIN', 'Admin')], default='MEMBER', max_length=20)),
                ('is_muted', models.BooleanField(default=False)),
                ('muted_until', models.DateTimeField(blank=True, null=True)),
                ('notification_enabled', models.BooleanField(default=True)),
                ('last_read_at', models.DateTimeField(blank=True, null=True)),
                ('pinned', models.BooleanField(default=False)),
                ('public_key', models.TextField(blank=True, null=True)),
                ('private_key_encrypted', models.TextField(blank=True, null=True)),
                ('joined_at', models.DateTimeField(auto_now_add=True)),
                ('left_at', models.DateTimeField(blank=True, null=True)),
                ('last_active_at', models.DateTimeField(auto_now=True)),
                ('is_active', models.BooleanField(default=True)),
                ('parent', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='chat_participations', to='people.parent')),
            ],
            options={
                'db_table': 'chat_participant_parents',
            },
        ),
        migrations.CreateModel(
            name='ChatParticipantStudent',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('role', models.CharField(choices=[('MEMBER', 'Member'), ('MODERATOR', 'Moderator'), ('ADMIN', 'Admin')], default='MEMBER', max_length=20)),
                ('is_muted', models.BooleanField(default=False)),
                ('muted_until', models.DateTimeField(blank=True, null=True)),
                ('notification_enabled', models.BooleanField(default=True)),
                ('last_read_at', models.DateTimeField(blank=True, null=True)),
                ('pinned', models.BooleanField(default=False)),
                ('public_key', models.TextField(blank=True, null=True)),
                ('private_key_encrypted', models.TextField(blank=True, null=True)),
                ('joined_at', models.DateTimeField(auto_now_add=True)),
                ('left_at', models.DateTimeField(blank=True, null=True)),
                ('last_active_at', models.DateTimeField(auto_now=True)),
                ('is_active', models.BooleanField(default=True)),
                ('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='chat_participations', to='people.student')),
            ],
            options={
                'db_table': 'chat_participant_students',
            },
        ),
        migrations.CreateModel(
            name='ChatParticipantTeacher',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('role', models.CharField(choices=[('MEMBER', 'Member'), ('MODERATOR', 'Moderator'), ('ADMIN', 'Admin')], default='MEMBER', max_length=20)),
                ('is_muted', models.BooleanField(default=False)),
                ('muted_until', models.DateTimeField(blank=True, null=True)),
                ('notification_enabled', models.BooleanField(default=True)),
                ('last_read_at', models.DateTimeField(blank=True, null=True)),
                ('pinned', models.BooleanField(default=False)),
                ('public_key', models.TextField(blank=True, null=True)),
                ('private_key_encrypted', models.TextField(blank=True, null=True)),
                ('joined_at', models.DateTimeField(auto_now_add=True)),
                ('left_at', models.DateTimeField(blank=True, null=True)),
                ('last_active_at', models.DateTimeField(auto_now=True)),
                ('is_active', models.BooleanField(default=True)),
                ('teacher', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='chat_participations', to='people.teacher')),
            ],
            options={
                'db_table': 'chat_participant_teachers',
            },
        ),
        migrations.CreateModel(
            name='ChatRoom',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('room_type', models.CharField(choices=[('INDIVIDUAL', 'Individual'), ('GROUP', 'Group'), ('CLASS', 'Class'), ('SUBJECT', 'Subject'), ('PARENT_TEACHER', 'Parent-Teacher'), ('STUDENT_GROUP', 'Student Group'), ('TEACHER_GROUP', 'Teacher Group')], default='INDIVIDUAL', max_length=20)),
                ('name', models.CharField(blank=True, help_text='For group chats', max_length=255, null=True)),
                ('description', models.TextField(blank=True, null=True)),
                ('is_encrypted', models.BooleanField(default=True, help_text='Enable end-to-end encryption')),
                ('encryption_key', models.TextField(blank=True, help_text='Encrypted room key', null=True)),
                ('admins', models.JSONField(default=list, help_text='List of admin user IDs with types')),
                ('moderators', models.JSONField(default=list, help_text='List of moderator user IDs with types')),
                ('created_by_type', models.CharField(blank=True, max_length=20, null=True)),
                ('created_by_id', models.CharField(blank=True, max_length=100, null=True)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('is_active', models.BooleanField(default=True)),
                ('last_message_at', models.DateTimeField(blank=True, null=True)),
                ('allow_media', models.BooleanField(default=True)),
                ('allow_links', models.BooleanField(default=True)),
                ('slow_mode', models.IntegerField(default=0, help_text='Seconds between messages')),
                ('join_by_invite_only', models.BooleanField(default=False)),
                ('academic_class', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='chat_rooms', to='academics.academicclass')),
                ('academic_year', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='chat_rooms', to='academics.academicyear')),
                ('parents', models.ManyToManyField(blank=True, related_name='chat_rooms', through='chat.ChatParticipantParent', to='people.parent')),
                ('students', models.ManyToManyField(blank=True, related_name='chat_rooms', through='chat.ChatParticipantStudent', to='people.student')),
                ('subject', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='chat_rooms', to='academics.subject')),
                ('subject_group', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='chat_rooms', to='academics.subjectgroup')),
                ('teachers', models.ManyToManyField(blank=True, related_name='chat_rooms', through='chat.ChatParticipantTeacher', to='people.teacher')),
            ],
            options={
                'db_table': 'chat_rooms',
                'ordering': ['-last_message_at'],
            },
        ),
        migrations.AddField(
            model_name='chatparticipantteacher',
            name='room',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_set', to='chat.chatroom'),
        ),
        migrations.AddField(
            model_name='chatparticipantstudent',
            name='room',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_set', to='chat.chatroom'),
        ),
        migrations.AddField(
            model_name='chatparticipantparent',
            name='room',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(class)s_set', to='chat.chatroom'),
        ),
        migrations.CreateModel(
            name='ChatInvitation',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('user_type', models.CharField(max_length=20)),
                ('user_id', models.CharField(max_length=100)),
                ('invited_by_type', models.CharField(max_length=20)),
                ('invited_by_id', models.CharField(max_length=100)),
                ('status', models.CharField(choices=[('PENDING', 'Pending'), ('ACCEPTED', 'Accepted'), ('REJECTED', 'Rejected'), ('EXPIRED', 'Expired')], default='PENDING', max_length=20)),
                ('expires_at', models.DateTimeField()),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('room', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='invitations', to='chat.chatroom')),
            ],
            options={
                'db_table': 'chat_invitations',
            },
        ),
        migrations.CreateModel(
            name='Message',
            fields=[
                ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('sender_type', models.CharField(max_length=20)),
                ('sender_id', models.CharField(max_length=100)),
                ('message_type', models.CharField(choices=[('TEXT', 'Text'), ('IMAGE', 'Image'), ('FILE', 'File'), ('AUDIO', 'Audio'), ('VIDEO', 'Video'), ('SYSTEM', 'System'), ('POLL', 'Poll'), ('ANNOUNCEMENT', 'Announcement'), ('ASSIGNMENT', 'Assignment')], default='TEXT', max_length=20)),
                ('content_encrypted', models.TextField(blank=True, null=True)),
                ('content', models.TextField(blank=True, null=True)),
                ('file', models.FileField(blank=True, null=True, upload_to='chat_files/%Y/%m/%d/')),
                ('file_name', models.CharField(blank=True, max_length=255, null=True)),
                ('file_size', models.IntegerField(blank=True, null=True)),
                ('file_type', models.CharField(blank=True, max_length=100, null=True)),
                ('thumbnail', models.ImageField(blank=True, null=True, upload_to='chat_thumbnails/%Y/%m/%d/')),
                ('is_encrypted', models.BooleanField(default=False)),
                ('is_read', models.BooleanField(default=False)),
                ('read_at', models.DateTimeField(blank=True, null=True)),
                ('is_deleted', models.BooleanField(default=False)),
                ('deleted_at', models.DateTimeField(blank=True, null=True)),
                ('deleted_by_type', models.CharField(blank=True, max_length=20, null=True)),
                ('deleted_by_id', models.CharField(blank=True, max_length=100, null=True)),
                ('edited_at', models.DateTimeField(blank=True, null=True)),
                ('edit_history', models.JSONField(default=list)),
                ('reactions', models.JSONField(default=dict)),
                ('metadata', models.JSONField(default=dict)),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('updated_at', models.DateTimeField(auto_now=True)),
                ('reply_to', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='replies', to='chat.message')),
                ('room', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='messages', to='chat.chatroom')),
            ],
            options={
                'db_table': 'messages',
                'ordering': ['created_at'],
            },
        ),
        migrations.CreateModel(
            name='ChatPoll',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('question', models.CharField(max_length=500)),
                ('options', models.JSONField()),
                ('is_multiple', models.BooleanField(default=False)),
                ('is_anonymous', models.BooleanField(default=False)),
                ('ends_at', models.DateTimeField()),
                ('created_by_type', models.CharField(max_length=20)),
                ('created_by_id', models.CharField(max_length=100)),
                ('total_votes', models.IntegerField(default=0)),
                ('message', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='poll', to='chat.message')),
            ],
            options={
                'db_table': 'chat_polls',
            },
        ),
        migrations.CreateModel(
            name='ChatMention',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('user_type', models.CharField(max_length=20)),
                ('user_id', models.CharField(max_length=100)),
                ('is_notified', models.BooleanField(default=False)),
                ('notified_at', models.DateTimeField(blank=True, null=True)),
                ('message', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='mentions', to='chat.message')),
            ],
            options={
                'db_table': 'chat_mentions',
            },
        ),
        migrations.CreateModel(
            name='MessageDelivery',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('user_type', models.CharField(max_length=20)),
                ('user_id', models.CharField(max_length=100)),
                ('status', models.CharField(choices=[('SENT', 'Sent'), ('DELIVERED', 'Delivered'), ('READ', 'Read'), ('FAILED', 'Failed')], default='SENT', max_length=20)),
                ('delivered_at', models.DateTimeField(blank=True, null=True)),
                ('read_at', models.DateTimeField(blank=True, null=True)),
                ('failed_reason', models.TextField(blank=True, null=True)),
                ('message', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='delivery_status', to='chat.message')),
            ],
            options={
                'db_table': 'message_delivery',
            },
        ),
        migrations.CreateModel(
            name='MessageReadReceipt',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('user_type', models.CharField(max_length=20)),
                ('user_id', models.CharField(max_length=100)),
                ('read_at', models.DateTimeField(auto_now_add=True)),
                ('message', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='read_receipts', to='chat.message')),
            ],
            options={
                'db_table': 'message_read_receipts',
            },
        ),
        migrations.CreateModel(
            name='ChatPollVote',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('user_type', models.CharField(max_length=20)),
                ('user_id', models.CharField(max_length=100)),
                ('option_index', models.IntegerField()),
                ('voted_at', models.DateTimeField(auto_now_add=True)),
                ('poll', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='votes', to='chat.chatpoll')),
            ],
            options={
                'db_table': 'chat_poll_votes',
                'unique_together': {('poll', 'user_type', 'user_id')},
            },
        ),
        migrations.AddIndex(
            model_name='chatroom',
            index=models.Index(fields=['room_type'], name='chat_rooms_room_ty_c8c67a_idx'),
        ),
        migrations.AddIndex(
            model_name='chatroom',
            index=models.Index(fields=['academic_class'], name='chat_rooms_academi_2a0e3c_idx'),
        ),
        migrations.AddIndex(
            model_name='chatroom',
            index=models.Index(fields=['subject'], name='chat_rooms_subject_462d07_idx'),
        ),
        migrations.AddIndex(
            model_name='chatroom',
            index=models.Index(fields=['is_active'], name='chat_rooms_is_acti_8486a3_idx'),
        ),
        migrations.AddIndex(
            model_name='chatroom',
            index=models.Index(fields=['last_message_at'], name='chat_rooms_last_me_a06a9d_idx'),
        ),
        migrations.AddIndex(
            model_name='chatparticipantteacher',
            index=models.Index(fields=['teacher', 'is_active'], name='chat_partic_teacher_0b18ac_idx'),
        ),
        migrations.AddIndex(
            model_name='chatparticipantteacher',
            index=models.Index(fields=['is_muted'], name='chat_partic_is_mute_146161_idx'),
        ),
        migrations.AddIndex(
            model_name='chatparticipantteacher',
            index=models.Index(fields=['role'], name='chat_partic_role_70ada3_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='chatparticipantteacher',
            unique_together={('room', 'teacher')},
        ),
        migrations.AddIndex(
            model_name='chatparticipantstudent',
            index=models.Index(fields=['student', 'is_active'], name='chat_partic_student_985713_idx'),
        ),
        migrations.AddIndex(
            model_name='chatparticipantstudent',
            index=models.Index(fields=['is_muted'], name='chat_partic_is_mute_491a7e_idx'),
        ),
        migrations.AddIndex(
            model_name='chatparticipantstudent',
            index=models.Index(fields=['role'], name='chat_partic_role_f42382_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='chatparticipantstudent',
            unique_together={('room', 'student')},
        ),
        migrations.AddIndex(
            model_name='chatparticipantparent',
            index=models.Index(fields=['parent', 'is_active'], name='chat_partic_parent__e603d6_idx'),
        ),
        migrations.AddIndex(
            model_name='chatparticipantparent',
            index=models.Index(fields=['is_muted'], name='chat_partic_is_mute_a9e1d1_idx'),
        ),
        migrations.AddIndex(
            model_name='chatparticipantparent',
            index=models.Index(fields=['role'], name='chat_partic_role_916d22_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='chatparticipantparent',
            unique_together={('room', 'parent')},
        ),
        migrations.AddIndex(
            model_name='chatinvitation',
            index=models.Index(fields=['user_type', 'user_id', 'status'], name='chat_invita_user_ty_e83b0e_idx'),
        ),
        migrations.AddIndex(
            model_name='chatinvitation',
            index=models.Index(fields=['expires_at'], name='chat_invita_expires_039695_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='chatinvitation',
            unique_together={('room', 'user_type', 'user_id')},
        ),
        migrations.AddIndex(
            model_name='message',
            index=models.Index(fields=['room', 'created_at'], name='messages_room_id_72ec70_idx'),
        ),
        migrations.AddIndex(
            model_name='message',
            index=models.Index(fields=['sender_type', 'sender_id'], name='messages_sender__d0d511_idx'),
        ),
        migrations.AddIndex(
            model_name='message',
            index=models.Index(fields=['is_read'], name='messages_is_read_6a69c0_idx'),
        ),
        migrations.AddIndex(
            model_name='message',
            index=models.Index(fields=['message_type'], name='messages_message_5af74b_idx'),
        ),
        migrations.AddIndex(
            model_name='chatmention',
            index=models.Index(fields=['user_type', 'user_id'], name='chat_mentio_user_ty_6169b0_idx'),
        ),
        migrations.AddIndex(
            model_name='chatmention',
            index=models.Index(fields=['is_notified'], name='chat_mentio_is_noti_c89710_idx'),
        ),
        migrations.AddIndex(
            model_name='messagedelivery',
            index=models.Index(fields=['user_type', 'user_id', 'status'], name='message_del_user_ty_40d514_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='messagedelivery',
            unique_together={('message', 'user_type', 'user_id')},
        ),
        migrations.AddIndex(
            model_name='messagereadreceipt',
            index=models.Index(fields=['user_type', 'user_id'], name='message_rea_user_ty_7eb9ec_idx'),
        ),
        migrations.AlterUniqueTogether(
            name='messagereadreceipt',
            unique_together={('message', 'user_type', 'user_id')},
        ),
    ]
