<?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::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('member_code')->unique();
            $table->string('referral_code')->unique();
            $table->string('name');
            $table->string('email')->nullable()->index();
            $table->string('mobile', 20)->nullable()->index();
            $table->enum('role', ['admin', 'user', 'franchise'])->default('user')->index();
            $table->enum('status', ['pending', 'active', 'blocked'])->default('pending')->index();
            $table->foreignId('sponsor_id')->nullable()->constrained('users')->nullOnDelete();
            $table->foreignId('placement_parent_id')->nullable()->constrained('users')->nullOnDelete();
            $table->enum('placement_leg', ['left', 'right'])->nullable();
            $table->decimal('package_amount', 12, 2)->default(0);
            $table->unsignedBigInteger('current_rank_id')->nullable()->index();
            $table->timestamp('joined_at')->nullable();
            $table->timestamp('last_login_at')->nullable();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('users');
    }
};
