<?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
    {
        if (Schema::hasTable('countries')) {
            Schema::table('countries', function (Blueprint $table) {
                // Check if the column does not already exist
                if (!Schema::hasColumn('countries', 'dial_code')) {
                    $table->string('dial_code')->nullable()->comment('Country dialing code');
                }
            });
        }
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        if (Schema::hasTable('countries')) {
            Schema::table('countries', function (Blueprint $table) {
                // Check if the column exists before dropping
                if (Schema::hasColumn('countries', 'dial_code')) {
                    $table->dropColumn('dial_code');
                }
            });
        }
    }
};
