<?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('payments', function (Blueprint $table) {
            if (!Schema::hasColumn('payments', 'payment_method')) {
                // Payment method used
                $table->enum('payment_method', [
                    'paystack',
                    'bank_transfer',
                    'cash',
                    'other'
                ])->default('paystack')->after('gateway');
            }

            if (!Schema::hasColumn('payments', 'verified_by')) {
                // Manual verification fields
                $table->foreignId('verified_by')->nullable()->constrained('users')->after('paid_at');
            }

            if (!Schema::hasColumn('payments', 'verified_at')) {
                $table->timestamp('verified_at')->nullable()->after('verified_by');
            }

            if (!Schema::hasColumn('payments', 'proof_of_payment_path')) {
                // Proof of payment (for manual methods)
                $table->string('proof_of_payment_path')->nullable()->after('verified_at');
            }

            if (!Schema::hasColumn('payments', 'payment_notes')) {
                // Additional notes from admin or member
                $table->text('payment_notes')->nullable()->after('proof_of_payment_path');
            }
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('payments', function (Blueprint $table) {
            $table->dropForeign(['verified_by']);
            $table->dropColumn([
                'payment_method',
                'verified_by',
                'verified_at',
                'proof_of_payment_path',
                'payment_notes',
            ]);
        });
    }
};
