# 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="Board",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "board_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        unique=True,
                        verbose_name="ID доски",
                    ),
                ),
                ("title", models.CharField(max_length=255, verbose_name="Название")),
                ("description", models.TextField(blank=True, verbose_name="Описание")),
                (
                    "access_type",
                    models.CharField(
                        choices=[
                            ("private", "Приватная"),
                            ("lesson", "Для занятия"),
                            ("public", "Публичная"),
                        ],
                        db_index=True,
                        default="private",
                        max_length=20,
                        verbose_name="Тип доступа",
                    ),
                ),
                (
                    "background_color",
                    models.CharField(
                        default="#FFFFFF", max_length=7, verbose_name="Цвет фона"
                    ),
                ),
                (
                    "grid_enabled",
                    models.BooleanField(default=True, verbose_name="Сетка включена"),
                ),
                (
                    "width",
                    models.IntegerField(default=5000, verbose_name="Ширина (px)"),
                ),
                (
                    "height",
                    models.IntegerField(default=5000, verbose_name="Высота (px)"),
                ),
                (
                    "is_active",
                    models.BooleanField(
                        db_index=True, default=True, verbose_name="Активна"
                    ),
                ),
                (
                    "is_template",
                    models.BooleanField(default=False, verbose_name="Шаблон"),
                ),
                (
                    "tldraw_snapshot",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text="Полное состояние Tldraw доски",
                        verbose_name="Tldraw состояние",
                    ),
                ),
                (
                    "views_count",
                    models.IntegerField(
                        default=0, verbose_name="Количество просмотров"
                    ),
                ),
                (
                    "elements_count",
                    models.IntegerField(default=0, verbose_name="Количество элементов"),
                ),
                (
                    "last_edited_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="Дата обновления"),
                ),
                (
                    "last_edited_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="last_edited_boards",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Последний редактор",
                    ),
                ),
                (
                    "lesson",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="boards",
                        to="schedule.lesson",
                        verbose_name="Занятие",
                    ),
                ),
                (
                    "mentor",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="mentor_boards",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Ментор",
                    ),
                ),
                (
                    "owner",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="owned_boards",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Владелец",
                    ),
                ),
                (
                    "participants",
                    models.ManyToManyField(
                        blank=True,
                        related_name="boards",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Участники",
                    ),
                ),
                (
                    "student",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="student_boards",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Студент",
                    ),
                ),
            ],
            options={
                "verbose_name": "Доска",
                "verbose_name_plural": "Доски",
                "db_table": "boards",
                "ordering": ["-last_edited_at", "-created_at"],
            },
        ),
        migrations.CreateModel(
            name="BoardSnapshot",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("snapshot_data", models.JSONField(verbose_name="Данные снимка")),
                (
                    "description",
                    models.CharField(
                        blank=True, max_length=255, verbose_name="Описание"
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True, verbose_name="Дата создания"
                    ),
                ),
                (
                    "board",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="snapshots",
                        to="board.board",
                        verbose_name="Доска",
                    ),
                ),
                (
                    "created_by",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="board_snapshots",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Автор",
                    ),
                ),
            ],
            options={
                "verbose_name": "Снимок доски",
                "verbose_name_plural": "Снимки досок",
                "db_table": "board_snapshots",
                "ordering": ["-created_at"],
            },
        ),
        migrations.CreateModel(
            name="BoardElement",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "element_type",
                    models.CharField(
                        choices=[
                            ("text", "Текст"),
                            ("shape", "Фигура"),
                            ("image", "Изображение"),
                            ("drawing", "Рисунок"),
                            ("sticky", "Стикер"),
                            ("arrow", "Стрелка"),
                            ("line", "Линия"),
                        ],
                        db_index=True,
                        max_length=20,
                        verbose_name="Тип элемента",
                    ),
                ),
                ("x", models.FloatField(verbose_name="Позиция X")),
                ("y", models.FloatField(verbose_name="Позиция Y")),
                ("width", models.FloatField(default=100, verbose_name="Ширина")),
                ("height", models.FloatField(default=100, verbose_name="Высота")),
                (
                    "rotation",
                    models.FloatField(default=0, verbose_name="Поворот (градусы)"),
                ),
                (
                    "z_index",
                    models.IntegerField(default=0, verbose_name="Z-индекс (слой)"),
                ),
                ("content", models.TextField(blank=True, verbose_name="Содержимое")),
                (
                    "font_size",
                    models.IntegerField(default=16, verbose_name="Размер шрифта"),
                ),
                (
                    "font_family",
                    models.CharField(
                        default="Arial", max_length=100, verbose_name="Шрифт"
                    ),
                ),
                (
                    "font_weight",
                    models.CharField(
                        default="normal", max_length=20, verbose_name="Жирность"
                    ),
                ),
                (
                    "text_align",
                    models.CharField(
                        default="left", max_length=20, verbose_name="Выравнивание"
                    ),
                ),
                (
                    "text_color",
                    models.CharField(
                        default="#000000", max_length=7, verbose_name="Цвет текста"
                    ),
                ),
                (
                    "shape_type",
                    models.CharField(
                        blank=True,
                        choices=[
                            ("rectangle", "Прямоугольник"),
                            ("circle", "Круг"),
                            ("triangle", "Треугольник"),
                            ("star", "Звезда"),
                        ],
                        max_length=20,
                        verbose_name="Тип фигуры",
                    ),
                ),
                (
                    "fill_color",
                    models.CharField(
                        default="#FFFFFF", max_length=7, verbose_name="Цвет заливки"
                    ),
                ),
                (
                    "stroke_color",
                    models.CharField(
                        default="#000000", max_length=7, verbose_name="Цвет границы"
                    ),
                ),
                (
                    "stroke_width",
                    models.FloatField(default=1, verbose_name="Толщина границы"),
                ),
                (
                    "opacity",
                    models.FloatField(default=1.0, verbose_name="Прозрачность (0-1)"),
                ),
                (
                    "image_url",
                    models.URLField(
                        blank=True, max_length=500, verbose_name="URL изображения"
                    ),
                ),
                (
                    "drawing_data",
                    models.TextField(blank=True, verbose_name="Данные рисунка"),
                ),
                (
                    "locked",
                    models.BooleanField(default=False, 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="Дата обновления"),
                ),
                (
                    "arrow_end_element",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="arrow_sources",
                        to="board.boardelement",
                        verbose_name="Конец стрелки",
                    ),
                ),
                (
                    "arrow_start_element",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="arrow_targets",
                        to="board.boardelement",
                        verbose_name="Начало стрелки",
                    ),
                ),
                (
                    "board",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="elements",
                        to="board.board",
                        verbose_name="Доска",
                    ),
                ),
                (
                    "created_by",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="board_elements",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Автор",
                    ),
                ),
                (
                    "locked_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="locked_elements",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="Заблокировал",
                    ),
                ),
            ],
            options={
                "verbose_name": "Элемент доски",
                "verbose_name_plural": "Элементы доски",
                "db_table": "board_elements",
                "ordering": ["z_index", "created_at"],
                "indexes": [
                    models.Index(
                        fields=["board", "is_deleted"],
                        name="board_eleme_board_i_725a9d_idx",
                    ),
                    models.Index(
                        fields=["element_type"], name="board_eleme_element_5c6211_idx"
                    ),
                    models.Index(
                        fields=["z_index"], name="board_eleme_z_index_2e5f56_idx"
                    ),
                ],
            },
        ),
        migrations.AddIndex(
            model_name="board",
            index=models.Index(fields=["board_id"], name="boards_board_i_980415_idx"),
        ),
        migrations.AddIndex(
            model_name="board",
            index=models.Index(
                fields=["owner", "is_active"], name="boards_owner_i_e9c6be_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="board",
            index=models.Index(fields=["lesson"], name="boards_lesson__a0967e_idx"),
        ),
        migrations.AddIndex(
            model_name="board",
            index=models.Index(
                fields=["mentor", "student"], name="boards_mentor__6310ad_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="board",
            index=models.Index(
                fields=["access_type", "is_active"], name="boards_access__9e9d8f_idx"
            ),
        ),
        migrations.AlterUniqueTogether(
            name="board",
            unique_together={("mentor", "student")},
        ),
    ]
