<?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::table('worlds', function (Blueprint $table): void {
            $table->boolean('is_active_campaign')->default(false)->after('is_featured');
            $table->boolean('is_homepage_featured')->default(false)->after('is_active_campaign');
            $table->integer('campaign_priority')->nullable()->after('is_homepage_featured');
            $table->string('campaign_label', 120)->nullable()->after('badge_label');
            $table->string('teaser_title', 180)->nullable()->after('summary');
            $table->string('teaser_summary', 320)->nullable()->after('teaser_title');
            $table->string('teaser_image_path', 2048)->nullable()->after('cover_path');
            $table->timestamp('promotion_starts_at')->nullable()->after('ends_at');
            $table->timestamp('promotion_ends_at')->nullable()->after('promotion_starts_at');

            $table->index(['status', 'is_active_campaign', 'campaign_priority'], 'worlds_activation_idx');
            $table->index(['is_homepage_featured', 'campaign_priority'], 'worlds_homepage_featured_idx');
            $table->index(['promotion_starts_at', 'promotion_ends_at'], 'worlds_promotion_window_idx');
        });
    }

    public function down(): void
    {
        Schema::table('worlds', function (Blueprint $table): void {
            $table->dropIndex('worlds_activation_idx');
            $table->dropIndex('worlds_homepage_featured_idx');
            $table->dropIndex('worlds_promotion_window_idx');
            $table->dropColumn([
                'is_active_campaign',
                'is_homepage_featured',
                'campaign_priority',
                'campaign_label',
                'teaser_title',
                'teaser_summary',
                'teaser_image_path',
                'promotion_starts_at',
                'promotion_ends_at',
            ]);
        });
    }
};