<?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 Layer: Just like Photoshop
        Schema::create('video_layers', function (Blueprint $table) {
            $table->id();
            $table->string('name')->nullable(); // layer name
            $table->foreignId('video_id'); // video this layer belongs to
            $table->foreignId('parent_id')->nullable(); // parent video id (for grouping)
            $table->foreignId('video_asset_id')->nullable(); // video asset this layer is associated with
            $table->foreignId('text_overlay_id')->nullable(); // text overlay this layer is associated with
            $table->double('time'); // if null, start from beginning
            $table->integer('track')->default(5); // track
            $table->double('duration'); // if null, end at end of video
            $table->integer('pos_x')->default(0); // absolute position of x
            $table->integer('pos_y')->default(0); // absolute position of y
            $table->float('scale_x')->default(1.0); // scale of x
            $table->float('scale_y')->default(1.0); // scale of y
            $table->enum('align_x', ['left', 'center', 'right'])->default('center'); // asset positioning alignment
            $table->enum('align_y', ['top', 'center', 'bottom'])->default('center'); // asset positioning alignment
            $table->jsonb('parameters')->nullable(); // settings, configs
            $table->timestamps();

            $table->foreign('video_id')->references('id')->on('videos')->onDelete('cascade');
            $table->foreign('parent_id')->references('id')->on('video_layers')->onDelete('set null');
            $table->foreign('video_asset_id')->references('id')->on('video_assets')->onDelete('set null');
            $table->foreign('text_overlay_id')->references('id')->on('text_overlays')->onDelete('set null');
        });
    }

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