<?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->foreignId('role_id')->nullable()->after('id')->constrained()->nullOnDelete();
            $table->string('mobile', 20)->nullable()->after('email')->unique();
            $table->string('status', 30)->default('active')->after('password');
            $table->decimal('wallet_balance', 12, 2)->default(0)->after('status');
            $table->string('referral_code')->nullable()->unique()->after('wallet_balance');
            $table->foreignId('referred_by')->nullable()->after('referral_code')->constrained('users')->nullOnDelete();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropConstrainedForeignId('referred_by');
            $table->dropConstrainedForeignId('role_id');
            $table->dropColumn(['mobile', 'status', 'wallet_balance', 'referral_code']);
        });
    }
};
