<?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::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('username')->unique();
            $table->string('fullname')->nullable();
            $table->string('email')->unique()->nullable();
            $table->string('password');
            $table->enum('role', ['owner', 'admin', 'reseller'])->default('reseller');
            $table->decimal('balance', 15, 2)->default(0);
            $table->boolean('is_blocked')->default(false);
            $table->string('device_id')->nullable();
            $table->unsignedBigInteger('referred_by')->nullable();
            $table->rememberToken();
            $table->timestamps();

            $table->foreign('referred_by')->references('id')->on('users')->onDelete('set null');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('users');
    }
};
