<?php

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

return new class extends Migration
{
    /**
     * Lookup tables that drive the employee form's Bank, Pension house and
     * Union dropdowns. Departments already have their own table. Values are
     * stored by name on the employee/bank/pension records so existing imports
     * keep working; these tables just curate the selectable options.
     */
    public function up(): void
    {
        foreach (['banks', 'pension_houses', 'unions'] as $table) {
            Schema::create($table, function (Blueprint $t) {
                $t->id();
                $t->string('name')->unique();
                $t->boolean('active')->default(true);
                $t->timestamps();
            });
        }

        // Give departments an active flag for parity with the other lookups.
        Schema::table('departments', function (Blueprint $t) {
            $t->boolean('active')->default(true)->after('code');
        });
    }

    public function down(): void
    {
        Schema::table('departments', function (Blueprint $t) {
            $t->dropColumn('active');
        });

        Schema::dropIfExists('unions');
        Schema::dropIfExists('pension_houses');
        Schema::dropIfExists('banks');
    }
};
