<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('upload_files', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->uuid('upload_id');
            $table->string('path');
            $table->string('type', 32)->index(); // main/screenshot/preview
            $table->string('hash', 128)->nullable()->index();
            $table->unsignedBigInteger('size')->nullable();
            $table->string('mime')->nullable();
            $table->timestamp('created_at')->useCurrent();

            $table->foreign('upload_id')->references('id')->on('uploads')->cascadeOnDelete();
            $table->index(['upload_id', 'type']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('upload_files');
    }
};
