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

import apps.homework.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):
    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="Homework",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("title", models.CharField(max_length=255, verbose_name="Название")),
                ("description", models.TextField(verbose_name="Описание задания")),
                (
                    "attachment",
                    models.FileField(
                        blank=True,
                        max_length=500,
                        upload_to=apps.homework.models.homework_file_upload_path,
                        verbose_name="Файл задания",
                    ),
                ),
                (
                    "attachment_url",
                    models.URLField(
                        blank=True, max_length=500, verbose_name="Ссылка на материал"
                    ),
                ),
                (
                    "deadline",
                    models.DateTimeField(
                        blank=True, db_index=True, null=True, verbose_name="Дедлайн"
                    ),
                ),
                (
                    "max_score",
                    models.IntegerField(
                        default=100,
                        validators=[django.core.validators.MinValueValidator(0)],
                        verbose_name="Максимальный балл",
                    ),
                ),
                (
                    "passing_score",
                    models.IntegerField(
                        default=60,
                        validators=[django.core.validators.MinValueValidator(0)],
                        verbose_name="Проходной балл",
                    ),
                ),
                (
                    "allow_late_submission",
                    models.BooleanField(
                        default=False, verbose_name="Разрешить сдачу после дедлайна"
                    ),
                ),
                (
                    "auto_check_enabled",
                    models.BooleanField(
                        default=False, verbose_name="Автоматическая проверка"
                    ),
                ),
                (
                    "ai_check_enabled",
                    models.BooleanField(default=False, verbose_name="AI проверка"),
                ),
                (
                    "requires_file",
                    models.BooleanField(default=True, verbose_name="Требуется файл"),
                ),
                (
                    "allowed_file_types",
                    models.CharField(
                        default=".pdf,.doc,.docx,.txt,.jpg,.png",
                        max_length=255,
                        verbose_name="Разрешенные типы файлов",
                    ),
                ),
                (
                    "max_file_size",
                    models.IntegerField(
                        default=10485760,
                        verbose_name="Максимальный размер файла (bytes)",
                    ),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("draft", "Черновик"),
                            ("published", "Опубликовано"),
                            ("archived", "В архиве"),
                        ],
                        db_index=True,
                        default="draft",
                        max_length=20,
                        verbose_name="Статус",
                    ),
                ),
                (
                    "total_submissions",
                    models.IntegerField(default=0, verbose_name="Всего решений"),
                ),
                (
                    "checked_submissions",
                    models.IntegerField(default=0, verbose_name="Проверено решений"),
                ),
                (
                    "average_score",
                    models.FloatField(default=0.0, verbose_name="Средний балл"),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, verbose_name="Дата создания"
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(auto_now=True, verbose_name="Дата обновления"),
                ),
                (
                    "published_at",
                    models.DateTimeField(
                        blank=True, null=True, verbose_name="Дата публикации"
                    ),
                ),
                (
                    "assigned_to",
                    models.ManyToManyField(
                        blank=True,
                        related_name="assigned_homeworks",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Назначено",
                    ),
                ),
            ],
            options={
                "verbose_name": "Домашнее задание",
                "verbose_name_plural": "Домашние задания",
                "db_table": "homeworks",
                "ordering": ["-created_at"],
            },
        ),
        migrations.CreateModel(
            name="HomeworkSubmission",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("content", models.TextField(blank=True, verbose_name="Текст решения")),
                (
                    "attachment",
                    models.FileField(
                        blank=True,
                        max_length=500,
                        upload_to=apps.homework.models.submission_file_upload_path,
                        verbose_name="Файл решения",
                    ),
                ),
                (
                    "attachment_url",
                    models.URLField(
                        blank=True, max_length=500, verbose_name="Ссылка на решение"
                    ),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("pending", "Ожидает проверки"),
                            ("checking", "На проверке"),
                            ("graded", "Проверено"),
                            ("returned", "Возвращено на доработку"),
                        ],
                        db_index=True,
                        default="pending",
                        max_length=20,
                        verbose_name="Статус",
                    ),
                ),
                (
                    "score",
                    models.IntegerField(
                        blank=True,
                        null=True,
                        validators=[django.core.validators.MinValueValidator(0)],
                        verbose_name="Балл",
                    ),
                ),
                ("passed", models.BooleanField(default=False, verbose_name="Сдано")),
                ("feedback", models.TextField(blank=True, verbose_name="Отзыв")),
                (
                    "checked_at",
                    models.DateTimeField(
                        blank=True, null=True, verbose_name="Дата проверки"
                    ),
                ),
                (
                    "ai_score",
                    models.IntegerField(blank=True, null=True, verbose_name="AI балл"),
                ),
                ("ai_feedback", models.TextField(blank=True, verbose_name="AI отзыв")),
                (
                    "ai_checked_at",
                    models.DateTimeField(
                        blank=True, null=True, verbose_name="Дата AI проверки"
                    ),
                ),
                (
                    "attempt_number",
                    models.IntegerField(default=1, verbose_name="Номер попытки"),
                ),
                (
                    "is_late",
                    models.BooleanField(
                        default=False, 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,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="checked_submissions",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Проверил",
                    ),
                ),
                (
                    "homework",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="submissions",
                        to="homework.homework",
                        verbose_name="Домашнее задание",
                    ),
                ),
                (
                    "student",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="homework_submissions",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Студент",
                    ),
                ),
            ],
            options={
                "verbose_name": "Решение ДЗ",
                "verbose_name_plural": "Решения ДЗ",
                "db_table": "homework_submissions",
                "ordering": ["-submitted_at"],
            },
        ),
        migrations.CreateModel(
            name="HomeworkFile",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "file_type",
                    models.CharField(
                        choices=[
                            ("assignment", "Файл задания"),
                            ("submission", "Файл решения"),
                            ("feedback", "Файл отзыва"),
                        ],
                        max_length=20,
                        verbose_name="Тип файла",
                    ),
                ),
                (
                    "file",
                    models.FileField(
                        max_length=500, upload_to="homework/files/", verbose_name="Файл"
                    ),
                ),
                (
                    "filename",
                    models.CharField(max_length=255, verbose_name="Название файла"),
                ),
                (
                    "file_size",
                    models.BigIntegerField(verbose_name="Размер файла (bytes)"),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, verbose_name="Дата загрузки"
                    ),
                ),
                (
                    "homework",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="files",
                        to="homework.homework",
                        verbose_name="Домашнее задание",
                    ),
                ),
                (
                    "submission",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="files",
                        to="homework.homeworksubmission",
                        verbose_name="Решение",
                    ),
                ),
                (
                    "uploaded_by",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="uploaded_homework_files",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Загрузил",
                    ),
                ),
            ],
            options={
                "verbose_name": "Файл ДЗ",
                "verbose_name_plural": "Файлы ДЗ",
                "db_table": "homework_files",
                "ordering": ["-created_at"],
            },
        ),
    ]
