<?php

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

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

        Schema::table('app_settings', function (Blueprint $table) {
            if (!Schema::hasColumn('app_settings', 'wallet_zain_cash_phone')) {
                $table->string('wallet_zain_cash_phone', 32)->nullable()->after('gas_subscription_enabled');
            }
            if (!Schema::hasColumn('app_settings', 'wallet_topup_instructions')) {
                $table->text('wallet_topup_instructions')->nullable()->after('wallet_zain_cash_phone');
            }
        });
    }

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

        Schema::table('app_settings', function (Blueprint $table) {
            if (Schema::hasColumn('app_settings', 'wallet_zain_cash_phone')) {
                $table->dropColumn('wallet_zain_cash_phone');
            }
            if (Schema::hasColumn('app_settings', 'wallet_topup_instructions')) {
                $table->dropColumn('wallet_topup_instructions');
            }
        });
    }
};
