<?php

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 Subtitle: Subtitles that can be overlaid on a video
        Schema::create('video_subtitles', function (Blueprint $table) {
            $table->id();
            $table->foreignId('video_id'); // video this subtitle belongs to
            $table->foreignId('video_data_id')->nullable(); // video data this subtitle is associated with
            $table->double('time'); // start time, if null, start from beginning
            $table->double('duration'); // end time, if null, end at end of video
            $table->text('text'); // text content
            $table->jsonb('payload')->nullable(); // font family, font size, font color, font weight, text align
            $table->timestamps();

            $table->foreign('video_id')->references('id')->on('videos')->onDelete('cascade');
            $table->foreign('video_data_id')->references('id')->on('video_datas')->onDelete('set null');
        });
    }

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