<?php

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

return new class extends Migration
{
    public function up(): void
    {
        if (! Schema::hasTable('wallet_ledgers')) {
            return;
        }

        $driver = DB::getDriverName();

        if ($driver === 'mysql') {
            DB::statement("
                ALTER TABLE wallet_ledgers
                MODIFY COLUMN source ENUM('purchase','refund','monnify','paystack','admin_adjust','cashback') NOT NULL
            ");
            return;
        }

        // SQLite/Postgres fallback for local tests if schema differs in future.
        // No-op because enum alteration syntax is driver-specific.
    }

    public function down(): void
    {
        if (! Schema::hasTable('wallet_ledgers')) {
            return;
        }

        $driver = DB::getDriverName();

        if ($driver === 'mysql') {
            DB::statement("
                ALTER TABLE wallet_ledgers
                MODIFY COLUMN source ENUM('purchase','refund','monnify','paystack','admin_adjust') NOT NULL
            ");
        }
    }
};

