<?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->foreignId('linked_challenge_id')->nullable()->after('parent_world_id')->constrained('group_challenges')->nullOnDelete();
            $table->boolean('show_linked_challenge_section')->default(true)->after('linked_challenge_id');
            $table->boolean('show_linked_challenge_entries')->default(true)->after('show_linked_challenge_section');
            $table->boolean('show_linked_challenge_winners')->default(true)->after('show_linked_challenge_entries');
            $table->boolean('show_linked_challenge_finalists')->default(true)->after('show_linked_challenge_winners');
            $table->boolean('auto_grant_challenge_world_rewards')->default(true)->after('show_linked_challenge_finalists');
            $table->text('challenge_teaser_override')->nullable()->after('auto_grant_challenge_world_rewards');
        });
    }

    public function down(): void
    {
        Schema::table('worlds', function (Blueprint $table): void {
            $table->dropConstrainedForeignId('linked_challenge_id');
            $table->dropColumn([
                'show_linked_challenge_section',
                'show_linked_challenge_entries',
                'show_linked_challenge_winners',
                'show_linked_challenge_finalists',
                'auto_grant_challenge_world_rewards',
                'challenge_teaser_override',
            ]);
        });
    }
};