<?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('sliders', function (Blueprint $table) {
            $table->id();
            $table->string('title', 191);
            // Image source: 'upload' for direct file upload, 'url' for external URL
            $table->enum('image_source', ['upload', 'url'])->default('url');
            // Stores either the file path (for uploads) or URL (for external links)
            $table->string('image_path', 500);
            // Stores the original filename for uploaded files
            $table->string('image_filename')->nullable();
            // File size in bytes (for uploaded files only)
            $table->bigInteger('image_size')->nullable();
            // MIME type of the image
            $table->string('image_mime_type', 100)->nullable();
            $table->string('status', 20)->default('draft'); // published | draft | archived
            $table->integer('order')->default(0);
            $table->timestamps();
            $table->softDeletes();

            $table->index('status');
            $table->index('order');
            $table->index('image_source');
            $table->index(['status', 'order']);
        });
    }

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