<?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', 40)->default('customer')->after('password');
            $table->string('phone', 40)->nullable()->after('role');
            $table->string('avatar')->nullable()->after('phone');
            $table->string('address')->nullable()->after('avatar');
            $table->string('department', 60)->nullable()->after('address');
            $table->string('status', 20)->default('active')->after('department');
            $table->string('referral_code', 20)->nullable()->unique()->after('status');
            $table->unsignedBigInteger('referred_by')->nullable()->after('referral_code');
            $table->timestamp('last_login_at')->nullable()->after('referred_by');
        });
    }

    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn([
                'role', 'phone', 'avatar', 'address', 'department', 'status',
                'referral_code', 'referred_by', 'last_login_at',
            ]);
        });
    }
};
