<?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('users', function (Blueprint $table) {
            $table->string('last_name')->nullable()->after('name');
            $table->string('username')->unique()->after('last_name');
            $table->string('phone')->nullable()->nullable()->after('email');
            $table->enum('type', ['admin', 'user'])->default('user')->after('phone');
            $table->renameColumn('name', 'first_name');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn(['last_name', 'username', 'phone', 'type']);
            $table->renameColumn('first_name', 'name');
        });
    }
};
