<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

/**
 * Add 'renewal_fee' to the membership_transactions.type enum.
 *
 * MySQL does not support ALTER COLUMN on enum directly via Blueprint,
 * so we use a raw SQL statement. This is safe and idempotent — if the
 * value already exists in the enum the statement is a no-op.
 */
return new class extends Migration
{
    public function up(): void
    {
        // Only run on MySQL/MariaDB — SQLite ignores enum constraints
        if (DB::getDriverName() === 'mysql') {
            DB::statement("
                ALTER TABLE membership_transactions
                MODIFY COLUMN type ENUM(
                    'subscription',
                    'contribution',
                    'loan_repayment',
                    'penalty',
                    'refund',
                    'disbursement',
                    'renewal_fee'
                ) NOT NULL
            ");
        }
    }

    public function down(): void
    {
        if (DB::getDriverName() === 'mysql') {
            DB::statement("
                ALTER TABLE membership_transactions
                MODIFY COLUMN type ENUM(
                    'subscription',
                    'contribution',
                    'loan_repayment',
                    'penalty',
                    'refund',
                    'disbursement'
                ) NOT NULL
            ");
        }
    }
};
