<?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('streamers', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->unique();
            $table->string('code')->unique();
            $table->decimal('percentage', 5, 2)->default(0)->comment('Commission percentage (e.g., 10.00 for 10%)');
            $table->bigInteger('total_gold_earned')->default(0)->comment('Total gold earned through referrals');
            $table->boolean('is_active')->default(true);
            $table->timestamps();

            // Note: No foreign key constraint due to custom user ID management with triggers
            $table->index('user_id');
            $table->index('code');
            $table->index('is_active');
        });
    }

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