<?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('users', function (Blueprint $table) {
            $table->string('role', 30)->after('password');
            $table->foreignId('region_id')->nullable()->after('role')->constrained()->nullOnDelete();
            $table->foreignId('branch_id')->nullable()->after('region_id')->constrained()->nullOnDelete();
            $table->boolean('is_active')->default(true)->after('branch_id');
            $table->timestamp('last_login_at')->nullable()->after('is_active');
            $table->softDeletes();
        });
    }

    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropConstrainedForeignId('region_id');
            $table->dropConstrainedForeignId('branch_id');
            $table->dropColumn(['role', 'is_active', 'last_login_at', 'deleted_at']);
        });
    }
};
