# Generated by Django 4.2.7 on 2025-12-09 21:02

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


class Migration(migrations.Migration):
    initial = True

    dependencies = [
        ("schedule", "0001_initial"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="VideoRoom",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "room_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        unique=True,
                        verbose_name="ID комнаты",
                    ),
                ),
                (
                    "sfu_type",
                    models.CharField(
                        choices=[
                            ("ion-sfu", "Ion SFU"),
                            ("janus", "Janus Gateway"),
                            ("livekit", "LiveKit"),
                        ],
                        default="ion-sfu",
                        help_text="Используемый SFU сервер (ion-sfu или janus)",
                        max_length=20,
                        verbose_name="Тип SFU",
                    ),
                ),
                (
                    "access_token",
                    models.CharField(
                        blank=True,
                        db_index=True,
                        help_text="Уникальный токен для входа в видеокомнату",
                        max_length=64,
                        unique=True,
                        verbose_name="Токен доступа",
                    ),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("waiting", "Ожидание"),
                            ("active", "Активна"),
                            ("ended", "Завершена"),
                        ],
                        db_index=True,
                        default="waiting",
                        max_length=20,
                        verbose_name="Статус",
                    ),
                ),
                (
                    "started_at",
                    models.DateTimeField(
                        blank=True, null=True, verbose_name="Время начала"
                    ),
                ),
                (
                    "ended_at",
                    models.DateTimeField(
                        blank=True, null=True, verbose_name="Время окончания"
                    ),
                ),
                (
                    "duration",
                    models.IntegerField(
                        blank=True,
                        help_text="Фактическая длительность видеозвонка",
                        null=True,
                        verbose_name="Длительность (секунды)",
                    ),
                ),
                (
                    "is_recording",
                    models.BooleanField(default=False, verbose_name="Запись включена"),
                ),
                (
                    "recording_url",
                    models.URLField(
                        blank=True, max_length=500, verbose_name="Ссылка на запись"
                    ),
                ),
                (
                    "router_id",
                    models.CharField(
                        blank=True, max_length=100, verbose_name="Mediasoup Router ID"
                    ),
                ),
                (
                    "mentor_joined_at",
                    models.DateTimeField(
                        blank=True, null=True, verbose_name="Ментор подключился"
                    ),
                ),
                (
                    "client_joined_at",
                    models.DateTimeField(
                        blank=True, null=True, verbose_name="Клиент подключился"
                    ),
                ),
                (
                    "max_participants",
                    models.IntegerField(default=2, verbose_name="Максимум участников"),
                ),
                (
                    "quality_rating",
                    models.IntegerField(
                        blank=True,
                        help_text="От 1 до 5",
                        null=True,
                        verbose_name="Оценка качества связи",
                    ),
                ),
                (
                    "quality_issues",
                    models.TextField(blank=True, verbose_name="Проблемы с качеством"),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, verbose_name="Дата создания"
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(auto_now=True, verbose_name="Дата обновления"),
                ),
                (
                    "client",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="client_video_rooms",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Клиент",
                    ),
                ),
                (
                    "lesson",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="video_room",
                        to="schedule.lesson",
                        verbose_name="Занятие",
                    ),
                ),
                (
                    "mentor",
                    models.ForeignKey(
                        limit_choices_to={"role": "mentor"},
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="mentor_video_rooms",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Ментор",
                    ),
                ),
            ],
            options={
                "verbose_name": "Видеокомната",
                "verbose_name_plural": "Видеокомнаты",
                "db_table": "video_rooms",
                "ordering": ["-created_at"],
            },
        ),
        migrations.CreateModel(
            name="VideoParticipant",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "connection_id",
                    models.CharField(
                        blank=True, max_length=100, verbose_name="Connection ID"
                    ),
                ),
                (
                    "send_transport_id",
                    models.CharField(
                        blank=True, max_length=100, verbose_name="Send Transport ID"
                    ),
                ),
                (
                    "recv_transport_id",
                    models.CharField(
                        blank=True, max_length=100, verbose_name="Receive Transport ID"
                    ),
                ),
                (
                    "is_connected",
                    models.BooleanField(default=False, verbose_name="Подключен"),
                ),
                (
                    "is_audio_enabled",
                    models.BooleanField(default=True, verbose_name="Аудио включено"),
                ),
                (
                    "is_video_enabled",
                    models.BooleanField(default=True, verbose_name="Видео включено"),
                ),
                (
                    "is_screen_sharing",
                    models.BooleanField(
                        default=False, verbose_name="Демонстрация экрана"
                    ),
                ),
                (
                    "joined_at",
                    models.DateTimeField(
                        auto_now_add=True, verbose_name="Время подключения"
                    ),
                ),
                (
                    "left_at",
                    models.DateTimeField(
                        blank=True, null=True, verbose_name="Время отключения"
                    ),
                ),
                (
                    "total_duration",
                    models.IntegerField(
                        default=0, verbose_name="Общее время (секунды)"
                    ),
                ),
                (
                    "reconnection_count",
                    models.IntegerField(
                        default=0, verbose_name="Количество переподключений"
                    ),
                ),
                (
                    "room",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="participants",
                        to="video.videoroom",
                        verbose_name="Комната",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="video_participations",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Пользователь",
                    ),
                ),
            ],
            options={
                "verbose_name": "Участник видео",
                "verbose_name_plural": "Участники видео",
                "db_table": "video_participants",
                "ordering": ["joined_at"],
            },
        ),
        migrations.CreateModel(
            name="VideoCallLog",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "total_participants",
                    models.IntegerField(default=0, verbose_name="Всего участников"),
                ),
                (
                    "total_duration",
                    models.IntegerField(
                        default=0, verbose_name="Общая длительность (секунды)"
                    ),
                ),
                (
                    "average_bitrate",
                    models.IntegerField(
                        blank=True, null=True, verbose_name="Средний битрейт (kbps)"
                    ),
                ),
                (
                    "packet_loss_rate",
                    models.FloatField(
                        blank=True, null=True, verbose_name="Процент потери пакетов"
                    ),
                ),
                (
                    "average_jitter",
                    models.IntegerField(
                        blank=True, null=True, verbose_name="Средний jitter (ms)"
                    ),
                ),
                (
                    "connection_issues",
                    models.IntegerField(
                        default=0, verbose_name="Проблем с подключением"
                    ),
                ),
                (
                    "audio_issues",
                    models.IntegerField(default=0, verbose_name="Проблем с аудио"),
                ),
                (
                    "video_issues",
                    models.IntegerField(default=0, verbose_name="Проблем с видео"),
                ),
                (
                    "metadata",
                    models.JSONField(
                        blank=True, default=dict, verbose_name="Метаданные"
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, verbose_name="Дата создания"
                    ),
                ),
                (
                    "room",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="call_logs",
                        to="video.videoroom",
                        verbose_name="Комната",
                    ),
                ),
            ],
            options={
                "verbose_name": "Лог видеозвонка",
                "verbose_name_plural": "Логи видеозвонков",
                "db_table": "video_call_logs",
                "ordering": ["-created_at"],
            },
        ),
        migrations.CreateModel(
            name="ScreenRecording",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "file_path",
                    models.CharField(
                        blank=True, max_length=500, verbose_name="Путь к файлу"
                    ),
                ),
                (
                    "file_size",
                    models.BigIntegerField(
                        blank=True, null=True, verbose_name="Размер файла (bytes)"
                    ),
                ),
                (
                    "duration",
                    models.IntegerField(
                        blank=True, null=True, verbose_name="Длительность (секунды)"
                    ),
                ),
                (
                    "url",
                    models.URLField(
                        blank=True, max_length=500, verbose_name="URL записи"
                    ),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("processing", "Обработка"),
                            ("ready", "Готово"),
                            ("failed", "Ошибка"),
                        ],
                        default="processing",
                        max_length=20,
                        verbose_name="Статус",
                    ),
                ),
                (
                    "processing_error",
                    models.TextField(blank=True, verbose_name="Ошибка обработки"),
                ),
                (
                    "is_public",
                    models.BooleanField(default=False, verbose_name="Публичная"),
                ),
                (
                    "expires_at",
                    models.DateTimeField(
                        blank=True,
                        help_text="После этой даты запись будет удалена",
                        null=True,
                        verbose_name="Истекает",
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, verbose_name="Дата создания"
                    ),
                ),
                (
                    "processed_at",
                    models.DateTimeField(
                        blank=True, null=True, verbose_name="Дата обработки"
                    ),
                ),
                (
                    "room",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="recordings",
                        to="video.videoroom",
                        verbose_name="Комната",
                    ),
                ),
            ],
            options={
                "verbose_name": "Запись видео",
                "verbose_name_plural": "Записи видео",
                "db_table": "screen_recordings",
                "ordering": ["-created_at"],
            },
        ),
        migrations.AddIndex(
            model_name="videoroom",
            index=models.Index(
                fields=["room_id"], name="video_rooms_room_id_eee920_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="videoroom",
            index=models.Index(
                fields=["mentor", "status"], name="video_rooms_mentor__a6bcf5_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="videoroom",
            index=models.Index(
                fields=["client", "status"], name="video_rooms_client__b79dc0_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="videoroom",
            index=models.Index(
                fields=["status", "created_at"], name="video_rooms_status_ec4f3f_idx"
            ),
        ),
        migrations.AlterUniqueTogether(
            name="videoparticipant",
            unique_together={("room", "user")},
        ),
    ]
