<?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('accepts_submissions')->default(false)->after('is_featured');
            $table->timestamp('submission_starts_at')->nullable()->after('ends_at');
            $table->timestamp('submission_ends_at')->nullable()->after('submission_starts_at');
            $table->boolean('submission_note_enabled')->default(true)->after('accepts_submissions');
            $table->boolean('community_section_enabled')->default(true)->after('submission_note_enabled');
            $table->text('submission_guidelines')->nullable()->after('badge_description');

            $table->index(['accepts_submissions', 'submission_starts_at', 'submission_ends_at'], 'worlds_submission_window_idx');
        });
    }

    public function down(): void
    {
        Schema::table('worlds', function (Blueprint $table): void {
            $table->dropIndex('worlds_submission_window_idx');
            $table->dropColumn([
                'accepts_submissions',
                'submission_starts_at',
                'submission_ends_at',
                'submission_note_enabled',
                'community_section_enabled',
                'submission_guidelines',
            ]);
        });
    }
};