<?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('images', function (Blueprint $table) {
            $table->id();

            // File information
            $table->string('title')->nullable();
            $table->string('alt_text')->nullable();
            $table->string('path'); // storage path
            $table->string('url');  // public URL
            $table->string('mime_type');
            $table->unsignedBigInteger('file_size'); // in bytes
            $table->integer('width')->nullable();
            $table->integer('height')->nullable();


            $table->timestamps();
        });

        Schema::create('imageables', function (Blueprint $table) {
            $table->id();

            $table->foreignId('image_id')->constrained()->cascadeOnDelete();
            $table->unsignedBigInteger('imageable_id');
            $table->string('imageable_type');

            $table->string('type')->nullable(); // room, icos-image, gallery

            $table->string('role')->nullable(); // thumbnail, gallery
            $table->integer('sort_order')->default(0);

            $table->timestamps();

            $table->index(['imageable_id', 'imageable_type']);
        });
    }


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