<?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
    {
        Schema::create('event_media_assets', function (Blueprint $table) {
            $table->id();
            $table->foreignId('event_id')->constrained()->cascadeOnDelete();
            $table->foreignId('media_storage_target_id')->constrained()->cascadeOnDelete();
            $table->foreignId('photo_id')->nullable()->constrained('photos')->nullOnDelete();
            $table->string('variant')->default('original'); // original, thumbnail, etc.
            $table->string('disk');
            $table->string('path');
            $table->unsignedBigInteger('size_bytes')->nullable();
            $table->string('checksum')->nullable();
            $table->string('mime_type')->nullable();
            $table->string('status')->default('pending'); // pending, hot, archived, restoring, failed
            $table->timestamp('processed_at')->nullable();
            $table->timestamp('archived_at')->nullable();
            $table->timestamp('restored_at')->nullable();
            $table->text('error_message')->nullable();
            $table->json('meta')->nullable();
            $table->timestamps();

            $table->index(['event_id', 'variant', 'status']);
            $table->index(['media_storage_target_id', 'status']);
        });
    }

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

