<?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('roulette_categories', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('slug')->unique();
        });

        Schema::create('roulette_items', function (Blueprint $table) {
            $table->id();
            $table->foreignId('roulette_category_id')->constrained()->cascadeOnDelete();
            $table->string('name');
            $table->string('image_path');
            // Probability weight — must be a positive integer, validated in
            // App\Http\Requests\Admin\StoreRouletteItemRequest (the legacy
            // app never validated this column at all).
            $table->unsignedInteger('weight');
            $table->unsignedInteger('value_min');
            $table->unsignedInteger('value_max');
            $table->timestamps();
        });

        Schema::create('roulette_drops', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->foreignId('roulette_item_id')->constrained()->cascadeOnDelete();
            $table->unsignedInteger('value');
            $table->timestamp('claimed_at')->nullable();
            $table->timestamp('created_at')->useCurrent();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('roulette_drops');
        Schema::dropIfExists('roulette_items');
        Schema::dropIfExists('roulette_categories');
    }
};
