<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('offline_payments', function (Blueprint $table) {
            if (!Schema::hasColumn('offline_payments', 'payment_date')) {
                $table->date('payment_date')->nullable()->after('submitted_at');
            }
            if (!Schema::hasColumn('offline_payments', 'transaction_reference')) {
                $table->string('transaction_reference')->nullable()->after('payment_date');
            }
            if (!Schema::hasColumn('offline_payments', 'user_notes')) {
                $table->text('user_notes')->nullable()->after('transaction_reference');
            }
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('offline_payments', function (Blueprint $table) {
            if (Schema::hasColumn('offline_payments', 'payment_date')) {
                $table->dropColumn('payment_date');
            }
            if (Schema::hasColumn('offline_payments', 'transaction_reference')) {
                $table->dropColumn('transaction_reference');
            }
            if (Schema::hasColumn('offline_payments', 'user_notes')) {
                $table->dropColumn('user_notes');
            }
        });
    }
};
