<?php

use App\Helpers\FirstParty\Render\RenderConstants;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        // Video: A single video that can be edited and saved
        Schema::create('videos', function (Blueprint $table) {
            $table->id();
            $table->uuid('uuid'); // uuid
            $table->foreignId('video_template_id')->nullable(); // is a template?
            $table->foreignId('user_id')->nullable(); // who owns it
            $table->string('title', 255); // title of video
            $table->string('type', 50); // moving_images, single_video, split_video, split_video_background_image
            $table->json('parameters'); // parameters for video (width, height, aspect ratio, frame rate)
            $table->enum('status', [RenderConstants::STATUS_COMPLETE, RenderConstants::STATUS_PROCESSING, RenderConstants::STATUS_ERROR]); // status of video
            $table->integer('processing_percentage')->default(0); // progress of processing
            $table->timestamps();

            $table->foreign('video_template_id')->references('id')->on('video_templates')->onDelete('set null');
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('videos');
    }
};
