<?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('balance_logs') || Schema::hasColumn('balance_logs', 'type')) {
            return;
        }

        Schema::table('balance_logs', function (Blueprint $table) {
            $table->string('type')->nullable()->after('amount')->index();
        });
    }

    public function down(): void
    {
        if (!Schema::hasTable('balance_logs') || !Schema::hasColumn('balance_logs', 'type')) {
            return;
        }

        Schema::table('balance_logs', function (Blueprint $table) {
            $table->dropIndex(['type']);
            $table->dropColumn('type');
        });
    }
};
