<?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 Asset: medias that may or maynot have video_data associated
        Schema::create('video_assets', function (Blueprint $table) {
            $table->id();
            $table->uuid('uuid'); // UUID that can be publicly shared
            $table->foreignId('video_id'); // video this asset belongs to
            $table->foreignId('video_data_id')->nullable(); // video data this asset is associated with
            $table->enum('media_type', ['image', 'video', 'audio']); // what kind of data is this?
            $table->string('mime_type'); // mime type of asset
            $table->string('name')->nullable(); // name of asset that can be pubicly shared
            $table->string('cloud_filename')->nullable(); // filename on cloud storage
            $table->integer('width')->nullable(); // for images and video: width of image
            $table->integer('height')->nullable();  // for images and video: height of image
            $table->float('aspect_ratio')->nullable(); // for images and video: aspect ratio of image
            $table->double('duration')->nullable(); // for audio and video assets: duration of asset
            $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_assets');
    }
};
