# Generated by Django 4.2.7 on 2025-12-15 14:52

import apps.schedule.models
from django.conf import settings
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("schedule", "0003_add_recurring_lessons"),
    ]

    operations = [
        migrations.CreateModel(
            name="LessonHomeworkSubmission",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "content",
                    models.TextField(
                        blank=True,
                        help_text="Текстовый ответ на домашнее задание",
                        verbose_name="Текст ответа",
                    ),
                ),
                (
                    "attachment",
                    models.FileField(
                        blank=True,
                        max_length=500,
                        null=True,
                        upload_to=apps.schedule.models.lesson_homework_submission_file_path,
                        validators=[
                            django.core.validators.FileExtensionValidator(
                                allowed_extensions=[
                                    "pdf",
                                    "doc",
                                    "docx",
                                    "txt",
                                    "jpg",
                                    "jpeg",
                                    "png",
                                    "zip",
                                    "rar",
                                ]
                            )
                        ],
                        verbose_name="Файл ответа",
                    ),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("pending", "Ожидает проверки"),
                            ("graded", "Проверено"),
                            ("returned", "Возвращено на доработку"),
                        ],
                        db_index=True,
                        default="pending",
                        max_length=20,
                        verbose_name="Статус",
                    ),
                ),
                (
                    "score",
                    models.IntegerField(
                        blank=True,
                        help_text="Оценка от 0 до 100",
                        null=True,
                        validators=[
                            django.core.validators.MinValueValidator(0),
                            django.core.validators.MaxValueValidator(100),
                        ],
                        verbose_name="Оценка",
                    ),
                ),
                (
                    "feedback",
                    models.TextField(blank=True, verbose_name="Отзыв ментора"),
                ),
                (
                    "checked_at",
                    models.DateTimeField(
                        blank=True, null=True, verbose_name="Дата проверки"
                    ),
                ),
                (
                    "submitted_at",
                    models.DateTimeField(
                        auto_now_add=True, verbose_name="Дата отправки"
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(auto_now=True, verbose_name="Дата обновления"),
                ),
                (
                    "checked_by",
                    models.ForeignKey(
                        blank=True,
                        limit_choices_to={"role": "mentor"},
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="checked_lesson_homework_submissions",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Проверил",
                    ),
                ),
                (
                    "lesson",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="homework_submissions",
                        to="schedule.lesson",
                        verbose_name="Урок",
                    ),
                ),
                (
                    "student",
                    models.ForeignKey(
                        limit_choices_to={"role": "client"},
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="lesson_homework_submissions",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Ученик",
                    ),
                ),
            ],
            options={
                "verbose_name": "Ответ на ДЗ по уроку",
                "verbose_name_plural": "Ответы на ДЗ по урокам",
                "db_table": "lesson_homework_submissions",
                "ordering": ["-submitted_at"],
                "indexes": [
                    models.Index(
                        fields=["lesson", "student"],
                        name="lesson_home_lesson__bd25fd_idx",
                    ),
                    models.Index(
                        fields=["student", "status"],
                        name="lesson_home_student_a64517_idx",
                    ),
                    models.Index(
                        fields=["status", "submitted_at"],
                        name="lesson_home_status_387722_idx",
                    ),
                ],
            },
        ),
        migrations.AddConstraint(
            model_name="lessonhomeworksubmission",
            constraint=models.UniqueConstraint(
                fields=("lesson", "student"), name="unique_lesson_student_submission"
            ),
        ),
    ]
