<?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
    {
        if (! Schema::hasTable('championship_teams')) {
            return;
        }

        Schema::table('championship_teams', function (Blueprint $table) {
            if (! Schema::hasColumn('championship_teams', 'is_confirmed')) {
                $table->boolean('is_confirmed')->default(false)->after('created_by_member_id');
                $table->index(['championship_id', 'is_confirmed'], 'ct_champ_confirmed_idx');
            }
        });
    }

    public function down(): void
    {
        if (! Schema::hasTable('championship_teams')) {
            return;
        }

        Schema::table('championship_teams', function (Blueprint $table) {
            if (Schema::hasColumn('championship_teams', 'is_confirmed')) {
                $table->dropIndex('ct_champ_confirmed_idx');
                $table->dropColumn('is_confirmed');
            }
        });
    }
};
