<?php

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

return new class extends Migration
{
    public function up()
    {
        Schema::table('fcf_reports_anagraficas', function (Blueprint $table) {
            // Drop existing columns if they exist
            if (Schema::hasColumn('fcf_reports_anagraficas', 'anag_foreign_birth_country')) {
                $table->dropColumn('anag_foreign_birth_country');
            }
            if (Schema::hasColumn('fcf_reports_anagraficas', 'anag_foreign_birth_city')) {
                $table->dropColumn('anag_foreign_birth_city');
            }
            if (Schema::hasColumn('fcf_reports_anagraficas', 'anag_foreign_residence_country')) {
                $table->dropColumn('anag_foreign_residence_country');
            }
            if (Schema::hasColumn('fcf_reports_anagraficas', 'anag_foreign_residence_city')) {
                $table->dropColumn('anag_foreign_residence_city');
            }

            // Add new columns
            $table->integer('anag_foreign_birth_country')->nullable();
            $table->string('anag_foreign_birth_city')->nullable();
            $table->integer('anag_foreign_residence_country')->nullable();
            $table->string('anag_foreign_residence_city')->nullable();
        });
    }

    public function down()
    {
        Schema::table('fcf_reports_anagraficas', function (Blueprint $table) {
            $table->dropColumn([
                'anag_foreign_birth_country',
                'anag_foreign_birth_city',
                'anag_foreign_residence_country',
                'anag_foreign_residence_city'
            ]);
        });
    }
};
