<?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('payments', function (Blueprint $table) {
            if (!Schema::hasColumn('payments', 'instrument_owner')) {
                $table->string('instrument_owner')->nullable()->after('payment_mode');
            }
            if (!Schema::hasColumn('payments', 'instrument_number')) {
                $table->string('instrument_number')->nullable()->after('instrument_owner');
            }
            if (Schema::hasColumn('payments', 'is_validated')) {
                $table->dropColumn('is_validated');
            }
        });
    }

    public function down(): void
    {
        Schema::table('payments', function (Blueprint $table) {
            if (Schema::hasColumn('payments', 'instrument_number')) {
                $table->dropColumn('instrument_number');
            }
            if (Schema::hasColumn('payments', 'instrument_owner')) {
                $table->dropColumn('instrument_owner');
            }
            if (!Schema::hasColumn('payments', 'is_validated')) {
                $table->boolean('is_validated')->default(false)->after('payment_mode');
            }
        });
    }
};


