<?php

declare(strict_types=1);

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('world_web_stories', function (Blueprint $table): void {
            $table->id();
            $table->foreignId('world_id')->nullable()->constrained('worlds')->nullOnDelete();
            $table->string('slug')->unique();
            $table->string('title');
            $table->string('subtitle')->nullable();
            $table->text('excerpt')->nullable();
            $table->text('description')->nullable();
            $table->string('seo_title')->nullable();
            $table->text('seo_description')->nullable();
            $table->string('poster_portrait_path')->nullable();
            $table->string('poster_square_path')->nullable();
            $table->string('publisher_logo_path')->nullable();
            $table->enum('status', ['draft', 'published', 'archived'])->default('draft');
            $table->boolean('featured')->default(false);
            $table->boolean('active')->default(true);
            $table->boolean('noindex')->default(false);
            $table->timestamp('published_at')->nullable();
            $table->timestamp('starts_at')->nullable();
            $table->timestamp('ends_at')->nullable();
            $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
            $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamps();
            $table->softDeletes();

            $table->index('world_id');
            $table->index('slug');
            $table->index(['status', 'active', 'published_at']);
            $table->index(['featured', 'status', 'active']);
        });
    }

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