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


class Migration(migrations.Migration):
    dependencies = [
        ("consultations", "0001_initial"),
    ]

    operations = [
        migrations.CreateModel(
            name="ConsultationSlot",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
                ("start_at", models.DateTimeField(unique=True, verbose_name="Начало консультации")),
                (
                    "duration_minutes",
                    models.PositiveSmallIntegerField(
                        choices=[(45, "45 минут"), (60, "60 минут"), (90, "90 минут"), (120, "120 минут")],
                        default=60,
                        verbose_name="Длительность, минут",
                    ),
                ),
                (
                    "subject",
                    models.CharField(
                        choices=[("any", "Физика или математика"), ("physics", "Физика"), ("mathematics", "Математика")],
                        default="any",
                        max_length=20,
                        verbose_name="Доступный предмет",
                    ),
                ),
                (
                    "format",
                    models.CharField(
                        choices=[("online", "Онлайн"), ("offline", "Очно")],
                        default="online",
                        max_length=20,
                        verbose_name="Формат",
                    ),
                ),
                ("is_active", models.BooleanField(default=True, verbose_name="Открыт для записи")),
                ("teacher_note", models.CharField(blank=True, max_length=300, verbose_name="Заметка преподавателя")),
                ("created_at", models.DateTimeField(auto_now_add=True, verbose_name="Создан")),
            ],
            options={
                "verbose_name": "Свободное время",
                "verbose_name_plural": "Расписание",
                "ordering": ("start_at",),
            },
        ),
        migrations.RemoveField(
            model_name="consultationrequest",
            name="is_processed",
        ),
        migrations.AddField(
            model_name="consultationrequest",
            name="cancellation_reason",
            field=models.CharField(blank=True, max_length=500, verbose_name="Причина отмены"),
        ),
        migrations.AddField(
            model_name="consultationrequest",
            name="consent_given",
            field=models.BooleanField(default=False, verbose_name="Согласие на обработку данных"),
        ),
        migrations.AddField(
            model_name="consultationrequest",
            name="format",
            field=models.CharField(
                choices=[("online", "Онлайн"), ("offline", "Очно"), ("any", "Не имеет значения")],
                default="online",
                max_length=20,
                verbose_name="Предпочтительный формат",
            ),
        ),
        migrations.AddField(
            model_name="consultationrequest",
            name="meeting_link",
            field=models.URLField(blank=True, verbose_name="Ссылка на встречу"),
        ),
        migrations.AddField(
            model_name="consultationrequest",
            name="reminder_sent",
            field=models.BooleanField(default=False, verbose_name="Напоминание отправлено"),
        ),
        migrations.AddField(
            model_name="consultationrequest",
            name="status",
            field=models.CharField(
                choices=[
                    ("new", "Новая"),
                    ("confirmed", "Подтверждена"),
                    ("completed", "Проведена"),
                    ("cancelled", "Отменена"),
                    ("no_show", "Не пришёл"),
                ],
                default="new",
                max_length=20,
                verbose_name="Статус",
            ),
        ),
        migrations.AddField(
            model_name="consultationrequest",
            name="student_grade",
            field=models.PositiveSmallIntegerField(
                blank=True,
                choices=[(5, "5 класс"), (6, "6 класс"), (7, "7 класс"), (8, "8 класс"), (9, "9 класс"), (10, "10 класс"), (11, "11 класс")],
                null=True,
                verbose_name="Класс ученика",
            ),
        ),
        migrations.AddField(
            model_name="consultationrequest",
            name="teacher_note",
            field=models.TextField(blank=True, max_length=2000, verbose_name="Заметка преподавателя"),
        ),
        migrations.AddField(
            model_name="consultationrequest",
            name="updated_at",
            field=models.DateTimeField(auto_now=True, verbose_name="Изменена"),
        ),
        migrations.AddField(
            model_name="consultationrequest",
            name="slot",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="bookings",
                to="consultations.consultationslot",
                verbose_name="Выбранное время",
            ),
        ),
        migrations.AlterField(
            model_name="consultationrequest",
            name="exam",
            field=models.CharField(
                choices=[("oge", "ОГЭ"), ("ege", "ЕГЭ"), ("school", "Школьная программа"), ("other", "Другая консультация")],
                max_length=20,
                verbose_name="Цель подготовки",
            ),
        ),
        migrations.AlterField(
            model_name="consultationrequest",
            name="comment",
            field=models.TextField(blank=True, max_length=1000, verbose_name="Комментарий ученика"),
        ),
        migrations.AlterField(
            model_name="consultationrequest",
            name="name",
            field=models.CharField(max_length=100, verbose_name="Имя ученика или родителя"),
        ),
        migrations.AlterField(
            model_name="consultationrequest",
            name="preferred_date",
            field=models.DateField(blank=True, null=True, verbose_name="Дата консультации"),
        ),
        migrations.AlterField(
            model_name="consultationrequest",
            name="preferred_time",
            field=models.TimeField(blank=True, null=True, verbose_name="Время консультации"),
        ),
        migrations.AlterModelOptions(
            name="consultationrequest",
            options={
                "ordering": ("preferred_date", "preferred_time", "-created_at"),
                "verbose_name": "Запись на консультацию",
                "verbose_name_plural": "Записи на консультации",
            },
        ),
        migrations.AddConstraint(
            model_name="consultationrequest",
            constraint=models.UniqueConstraint(
                condition=models.Q(("status__in", ("new", "confirmed"))),
                fields=("slot",),
                name="unique_active_slot_booking",
            ),
        ),
    ]
