<?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('payment_gateways', function (Blueprint $table) {
            // Drop old columns
            $table->dropColumn(['public_key', 'secret_key', 'webhook_secret']);
            
            // Add test credentials
            $table->text('test_publishable_key')->nullable()->after('enabled');
            $table->text('test_secret_key')->nullable()->after('test_publishable_key');
            $table->text('test_webhook_secret')->nullable()->after('test_secret_key');
            
            // Add live credentials
            $table->text('live_publishable_key')->nullable()->after('test_webhook_secret');
            $table->text('live_secret_key')->nullable()->after('live_publishable_key');
            $table->text('live_webhook_secret')->nullable()->after('live_secret_key');
            
            // Add mode flag
            $table->boolean('is_live_mode')->default(false)->after('live_webhook_secret');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('payment_gateways', function (Blueprint $table) {
            $table->dropColumn([
                'test_publishable_key',
                'test_secret_key',
                'test_webhook_secret',
                'live_publishable_key',
                'live_secret_key',
                'live_webhook_secret',
                'is_live_mode'
            ]);
            
            // Restore old columns
            $table->text('public_key')->nullable();
            $table->text('secret_key')->nullable();
            $table->text('webhook_secret')->nullable();
        });
    }
};
