<?php

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

return new class extends Migration
{
    /**
     * إضافة إعدادات محفظة السائق/المطعم/الغاز: زين كاش، ماستر كارد، بطاقة أمان
     */
    public function up(): void
    {
        if (!Schema::hasTable('app_settings')) {
            return;
        }

        Schema::table('app_settings', function (Blueprint $table) {
            if (!Schema::hasColumn('app_settings', 'wallet_mastercard_instructions')) {
                $table->text('wallet_mastercard_instructions')->nullable()->after('wallet_topup_instructions');
            }
            if (!Schema::hasColumn('app_settings', 'wallet_aman_card_enabled')) {
                $table->boolean('wallet_aman_card_enabled')->default(false)->after('wallet_mastercard_instructions');
            }
            if (!Schema::hasColumn('app_settings', 'wallet_aman_card_instructions')) {
                $table->text('wallet_aman_card_instructions')->nullable()->after('wallet_aman_card_enabled');
            }
        });
    }

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

        Schema::table('app_settings', function (Blueprint $table) {
            if (Schema::hasColumn('app_settings', 'wallet_mastercard_instructions')) {
                $table->dropColumn('wallet_mastercard_instructions');
            }
            if (Schema::hasColumn('app_settings', 'wallet_aman_card_enabled')) {
                $table->dropColumn('wallet_aman_card_enabled');
            }
            if (Schema::hasColumn('app_settings', 'wallet_aman_card_instructions')) {
                $table->dropColumn('wallet_aman_card_instructions');
            }
        });
    }
};
