<?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('payments') && ! Schema::hasColumn('payments', 'active')) {
            Schema::table('payments', function (Blueprint $table): void {
                $table->unsignedTinyInteger('active')->default(1)->after('type_id');
                $table->index('active');
            });
        }
    }

    public function down(): void
    {
        if (Schema::hasTable('payments') && Schema::hasColumn('payments', 'active')) {
            Schema::table('payments', function (Blueprint $table): void {
                $table->dropIndex(['active']);
                $table->dropColumn('active');
            });
        }
    }
};
