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

            $table->string('title', 150)->nullable()->comment('標題');
            $table->string('image_path', 255)->comment('圖片');
            $table->string('alt_text', 255)->nullable()->comment('替代文字');

            // link_url：點擊後導向（可為站內/站外）
            $table->text('link_url')->nullable()->comment('連結');
            $table->boolean('open_in_new_tab')->default(false)->comment('新分頁');

            // caption：可作為前台文字說明（選填）
            $table->string('caption', 255)->nullable()->comment('說明');

            // starts_at/ends_at：投放區間（選填）
            $table->timestamp('starts_at')->nullable()->comment('開始');
            $table->timestamp('ends_at')->nullable()->comment('結束');

            $table->unsignedInteger('sort_order')->default(0)->comment('排序');
            $table->boolean('is_active')->default(true)->comment('啟用');

            $table->timestamp('created_at')->nullable()->comment('建立');
            $table->timestamp('updated_at')->nullable()->comment('更新');
            $table->timestamp('deleted_at')->nullable()->comment('刪除');

            $table->index(['is_active', 'sort_order']);
            $table->index(['starts_at', 'ends_at']);
        });
    }

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