<?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('day_tour_images', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('day_tour_id');
            $table->unsignedBigInteger('disk_item_id')->nullable();

            // Image Information
            $table->string('image_url')->nullable();
            $table->string('thumbnail_url')->nullable();
            $table->string('title')->nullable();
            $table->text('description')->nullable();
            $table->string('alt_text')->nullable();

            // Image Type & Usage
            $table->enum('image_type', ['cover', 'gallery', 'featured', 'itinerary'])->default('gallery');
            $table->boolean('is_cover')->default(false);
            $table->boolean('is_featured')->default(false);
            $table->boolean('show_in_gallery')->default(true);
            $table->boolean('show_in_slider')->default(false);

            // Display Settings
            $table->integer('sort_order')->default(0);
            $table->string('section')->nullable()->comment('Which section to display: hero, gallery, itinerary, etc.');

            // Status & Approval
            $table->boolean('is_active')->default(true);
            $table->boolean('is_approved')->default(false);
            $table->timestamp('approved_at')->nullable();
            $table->unsignedBigInteger('approved_by')->nullable();

            $table->timestamps();
            $table->softDeletes();

            // Foreign Keys
            $table->foreign('day_tour_id')->references('id')->on('day_tours')->onDelete('cascade');
            $table->foreign('disk_item_id')->references('id')->on('disk_items')->onDelete('set null');
            $table->foreign('approved_by')->references('id')->on('users')->onDelete('set null');

            // Indexes
            $table->index(['day_tour_id', 'sort_order']);
            $table->index(['day_tour_id', 'is_active', 'is_approved']);
            $table->index(['image_type', 'is_active']);
            $table->index(['is_cover', 'is_active']);
        });
    }

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