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

            $table->foreignId('listing_id')
                ->constrained('listings')
                ->cascadeOnDelete();

            $table->string('file_path');
            $table->string('file_url')->nullable();

            $table->string('alt_text')->nullable();

            $table->string('mime_type')->nullable();
            $table->unsignedBigInteger('size')->nullable();

            $table->integer('sort_order')->default(0);
            $table->boolean('is_cover')->default(false);

            $table->timestamps();

            $table->index('is_cover');
        });
    }

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