<?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('departments', function (Blueprint $table) {
            if (! Schema::hasColumn('departments', 'type')) {
                $table->string('type')->default('department')->after('description');
            }
            if (! Schema::hasColumn('departments', 'manager_changed_at')) {
                $table->timestamp('manager_changed_at')->nullable()->after('manager_id');
            }
        });
    }

    public function down(): void
    {
        Schema::table('departments', function (Blueprint $table) {
            if (Schema::hasColumn('departments', 'manager_changed_at')) {
                $table->dropColumn('manager_changed_at');
            }
            if (Schema::hasColumn('departments', 'type')) {
                $table->dropColumn('type');
            }
        });
    }
};
