<?php

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

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

            $table->index(['tenant_id', 'manager_employee_id'], 'employees_tenant_manager_idx');
        });
    }

    public function down(): void
    {
        Schema::table('employees', function (Blueprint $table) {
            $table->dropIndex('employees_tenant_manager_idx');
            $table->dropConstrainedForeignId('manager_employee_id');
        });
    }
};

