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

import apps.materials.models
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
    initial = True

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

    operations = [
        migrations.CreateModel(
            name="Material",
            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(blank=True, verbose_name="Описание")),
                (
                    "file",
                    models.FileField(
                        blank=True,
                        max_length=500,
                        upload_to=apps.materials.models.material_file_upload_path,
                        verbose_name="Файл",
                    ),
                ),
                (
                    "file_name",
                    models.CharField(
                        blank=True, max_length=255, verbose_name="Имя файла"
                    ),
                ),
                (
                    "file_size",
                    models.BigIntegerField(
                        default=0, verbose_name="Размер файла (bytes)"
                    ),
                ),
                (
                    "file_type",
                    models.CharField(
                        blank=True, max_length=100, verbose_name="MIME тип"
                    ),
                ),
                (
                    "url",
                    models.URLField(blank=True, max_length=500, verbose_name="Ссылка"),
                ),
                (
                    "material_type",
                    models.CharField(
                        choices=[
                            ("document", "Документ"),
                            ("presentation", "Презентация"),
                            ("video", "Видео"),
                            ("audio", "Аудио"),
                            ("image", "Изображение"),
                            ("archive", "Архив"),
                            ("link", "Ссылка"),
                            ("other", "Другое"),
                        ],
                        db_index=True,
                        default="other",
                        max_length=20,
                        verbose_name="Тип материала",
                    ),
                ),
                (
                    "access_type",
                    models.CharField(
                        choices=[
                            ("private", "Приватный"),
                            ("public", "Публичный"),
                            ("lesson", "Для занятия"),
                            ("clients", "Для клиентов"),
                        ],
                        db_index=True,
                        default="private",
                        max_length=20,
                        verbose_name="Тип доступа",
                    ),
                ),
                (
                    "allow_download",
                    models.BooleanField(
                        default=True, verbose_name="Разрешить скачивание"
                    ),
                ),
                (
                    "is_featured",
                    models.BooleanField(default=False, verbose_name="Избранный"),
                ),
                (
                    "views_count",
                    models.IntegerField(
                        default=0, verbose_name="Количество просмотров"
                    ),
                ),
                (
                    "downloads_count",
                    models.IntegerField(
                        default=0, verbose_name="Количество скачиваний"
                    ),
                ),
                (
                    "is_deleted",
                    models.BooleanField(
                        db_index=True, default=False, verbose_name="Удален"
                    ),
                ),
                (
                    "deleted_at",
                    models.DateTimeField(
                        blank=True, null=True, verbose_name="Дата удаления"
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, verbose_name="Дата создания"
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(auto_now=True, verbose_name="Дата обновления"),
                ),
            ],
            options={
                "verbose_name": "Материал",
                "verbose_name_plural": "Материалы",
                "db_table": "materials",
                "ordering": ["-created_at"],
            },
        ),
        migrations.CreateModel(
            name="MaterialTag",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        max_length=50, unique=True, verbose_name="Название"
                    ),
                ),
                ("slug", models.SlugField(unique=True, verbose_name="Слаг")),
                (
                    "color",
                    models.CharField(
                        default="#007bff", max_length=7, verbose_name="Цвет"
                    ),
                ),
                (
                    "materials_count",
                    models.IntegerField(
                        default=0, verbose_name="Количество материалов"
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, verbose_name="Дата создания"
                    ),
                ),
            ],
            options={
                "verbose_name": "Тег материала",
                "verbose_name_plural": "Теги материалов",
                "db_table": "material_tags",
                "ordering": ["name"],
            },
        ),
        migrations.CreateModel(
            name="StorageQuota",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "total_quota",
                    models.BigIntegerField(
                        default=1073741824, verbose_name="Общая квота (bytes)"
                    ),
                ),
                (
                    "used_space",
                    models.BigIntegerField(
                        default=0, verbose_name="Использовано (bytes)"
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, verbose_name="Дата создания"
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(auto_now=True, verbose_name="Дата обновления"),
                ),
                (
                    "user",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="storage_quota",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Пользователь",
                    ),
                ),
            ],
            options={
                "verbose_name": "Квота хранилища",
                "verbose_name_plural": "Квоты хранилища",
                "db_table": "storage_quotas",
            },
        ),
        migrations.CreateModel(
            name="MaterialFolder",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("name", models.CharField(max_length=255, verbose_name="Название")),
                ("description", models.TextField(blank=True, verbose_name="Описание")),
                (
                    "is_public",
                    models.BooleanField(default=False, verbose_name="Публичная"),
                ),
                (
                    "materials_count",
                    models.IntegerField(
                        default=0, verbose_name="Количество материалов"
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, verbose_name="Дата создания"
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(auto_now=True, verbose_name="Дата обновления"),
                ),
                (
                    "owner",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="material_folders",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Владелец",
                    ),
                ),
                (
                    "parent",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="subfolders",
                        to="materials.materialfolder",
                        verbose_name="Родительская папка",
                    ),
                ),
                (
                    "shared_with",
                    models.ManyToManyField(
                        blank=True,
                        related_name="shared_folders",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Доступ предоставлен",
                    ),
                ),
            ],
            options={
                "verbose_name": "Папка материалов",
                "verbose_name_plural": "Папки материалов",
                "db_table": "material_folders",
                "ordering": ["name"],
            },
        ),
        migrations.CreateModel(
            name="MaterialAccess",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "action",
                    models.CharField(
                        choices=[
                            ("view", "Просмотр"),
                            ("download", "Скачивание"),
                            ("share", "Предоставление доступа"),
                        ],
                        max_length=20,
                        verbose_name="Действие",
                    ),
                ),
                (
                    "ip_address",
                    models.GenericIPAddressField(
                        blank=True, null=True, verbose_name="IP адрес"
                    ),
                ),
                (
                    "user_agent",
                    models.CharField(
                        blank=True, max_length=500, verbose_name="User Agent"
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, db_index=True, verbose_name="Дата"
                    ),
                ),
                (
                    "material",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="access_logs",
                        to="materials.material",
                        verbose_name="Материал",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="material_accesses",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Пользователь",
                    ),
                ),
            ],
            options={
                "verbose_name": "Лог доступа к материалу",
                "verbose_name_plural": "Логи доступа к материалам",
                "db_table": "material_access_logs",
                "ordering": ["-created_at"],
            },
        ),
        migrations.AddField(
            model_name="material",
            name="folder",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="materials",
                to="materials.materialfolder",
                verbose_name="Папка",
            ),
        ),
        migrations.AddField(
            model_name="material",
            name="homework",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="materials",
                to="homework.homework",
                verbose_name="Домашнее задание",
            ),
        ),
    ]
