<?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::table('worlds', function (Blueprint $table): void {
            $table->string('recap_status', 24)->default('draft')->after('published_at');
            $table->string('recap_title', 180)->nullable()->after('recap_status');
            $table->string('recap_summary', 320)->nullable()->after('recap_title');
            $table->text('recap_intro')->nullable()->after('recap_summary');
            $table->foreignId('recap_article_id')->nullable()->after('recap_intro')->constrained('news_articles')->nullOnDelete();
            $table->json('recap_stats_snapshot_json')->nullable()->after('recap_article_id');
            $table->timestamp('recap_published_at')->nullable()->after('recap_stats_snapshot_json');

            $table->index(['recap_status', 'recap_published_at'], 'worlds_recap_status_idx');
        });
    }

    public function down(): void
    {
        Schema::table('worlds', function (Blueprint $table): void {
            $table->dropIndex('worlds_recap_status_idx');
            $table->dropConstrainedForeignId('recap_article_id');
            $table->dropColumn([
                'recap_status',
                'recap_title',
                'recap_summary',
                'recap_intro',
                'recap_stats_snapshot_json',
                'recap_published_at',
            ]);
        });
    }
};