# Generated by Django 4.1.9 on 2023-07-06 16:05
import django.db.models.deletion
from django.apps.registry import Apps
from django.db import migrations, models

import wideo.storage


def up(apps: Apps, *args, **kwargs):
    pass


def down(apps: Apps, *args, **kwargs):
    UploadedVideo = apps.get_model("wideo", "UploadedVideo")

    if UploadedVideo.objects.count() > 0:
        raise RuntimeError(
            "UploadedVideo instances must be purged prior to downgrading, as fields without default values must be inserted back"
        )


class Migration(migrations.Migration):
    dependencies = [
        ("wideo", "0002_lock"),
    ]

    operations = [
        migrations.RemoveField(
            model_name="uploadedvideo",
            name="duration",
        ),
        migrations.RemoveField(
            model_name="uploadedvideo",
            name="file",
        ),
        migrations.RemoveField(
            model_name="uploadedvideo",
            name="frame_count",
        ),
        migrations.RemoveField(
            model_name="uploadedvideo",
            name="frames_per_second",
        ),
        migrations.RemoveField(
            model_name="uploadedvideo",
            name="height",
        ),
        migrations.RemoveField(
            model_name="uploadedvideo",
            name="mime",
        ),
        migrations.RemoveField(
            model_name="uploadedvideo",
            name="width",
        ),
        migrations.CreateModel(
            name="UploadedVideoChunk",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "index",
                    models.IntegerField(
                        help_text="The position of the chunk in the uploaded video",
                        verbose_name="index",
                    ),
                ),
                (
                    "file",
                    models.FileField(
                        help_text="The uploaded chunk",
                        upload_to=wideo.storage.upload_to,
                        verbose_name="file",
                    ),
                ),
                (
                    "video",
                    models.ForeignKey(
                        help_text="The video the chunk is part of",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="chunks",
                        to="wideo.uploadedvideo",
                        verbose_name="video",
                    ),
                ),
            ],
            options={
                "unique_together": {("video", "index")},
            },
        ),
        migrations.RunPython(up, down),
    ]
