<?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('cities')) {
            Schema::table('cities', function (Blueprint $table) {
                if (!Schema::hasColumn('cities', 'country_id')) {
                    $table->integer('country_id')->after('emirate_id')->nullable();
                }
                if (!Schema::hasColumn('cities', 'status')) {
                    $table->integer('status')->default(0)->after('country_id');
                }
            });
        }
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        if (Schema::hasTable('cities')) {
            Schema::table('cities', function (Blueprint $table) {
                if (Schema::hasColumn('cities', 'country_id')) {
                    $table->dropColumn('country_id');
                }
                if (Schema::hasColumn('cities', 'status')) {
                    $table->dropColumn('status');
                }
            });
        }
    }
};
