<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('employees', function (Blueprint $table) {
            $table->foreignId('employment_status_id')
                ->nullable()
                ->after('national_id')
                ->constrained('employment_statuses')
                ->nullOnDelete();
        });

        Schema::table('employee_addresses', function (Blueprint $table) {
            $table->foreignId('country_id')->nullable()->after('employee_id')
                ->constrained('geo_countries')->nullOnDelete();
            $table->foreignId('region_id')->nullable()->after('country_id')
                ->constrained('geo_regions')->nullOnDelete();
            $table->foreignId('city_id')->nullable()->after('region_id')
                ->constrained('geo_cities')->nullOnDelete();
        });
    }

    public function down(): void
    {
        Schema::table('employee_addresses', function (Blueprint $table) {
            $table->dropConstrainedForeignId('city_id');
            $table->dropConstrainedForeignId('region_id');
            $table->dropConstrainedForeignId('country_id');
        });

        Schema::table('employees', function (Blueprint $table) {
            $table->dropConstrainedForeignId('employment_status_id');
        });
    }
};
