<?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
    {
        Schema::table('departments', function (Blueprint $table) {
            if (!Schema::hasColumn('departments', 'company_id')) {
                $table->unsignedBigInteger('company_id')->after('id')->nullable();    // users.id of role_id=2
                $table->unsignedBigInteger('superadmin_id')->after('company_id')->nullable(); // users.id of role_id=1
            }
            if (!Schema::hasColumn('departments', 'head_email')) {
                $table->string('head_email')->nullable()->after('name');
            }
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('departments', function (Blueprint $table) {
            $table->dropColumn(['company_id', 'head_email']);
        });
    }
};
