<?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->uuid('public_id')->nullable()->unique()->after('id');
            $table->string('username')->nullable()->unique()->after('name');
            $table->string('display_name')->nullable()->after('username');
            $table->string('country_code', 2)->nullable()->after('email');
            $table->string('preferred_locale', 5)->default('en')->after('country_code');
            $table->string('timezone')->default('UTC')->after('preferred_locale');
            $table->string('phone_country_code', 5)->nullable()->after('timezone');
            $table->string('phone_number', 32)->nullable()->after('phone_country_code');
            $table->string('phone_e164', 20)->nullable()->after('phone_number');
            $table->timestamp('phone_verified_at')->nullable()->after('phone_e164');
            $table->string('role')->default('user')->after('phone_verified_at');
            $table->string('status')->default('active')->after('role');
            $table->timestamp('terms_accepted_at')->nullable()->after('status');
        });
    }

    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn([
                'public_id', 'username', 'display_name', 'country_code',
                'preferred_locale', 'timezone', 'phone_country_code',
                'phone_number', 'phone_e164', 'phone_verified_at',
                'role', 'status', 'terms_accepted_at',
            ]);
        });
    }
};
