<?php

declare(strict_types=1);

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('member_levels', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->foreignUuid('tenant_id')->constrained('tenants')->cascadeOnDelete();
            $table->unsignedTinyInteger('level');
            $table->string('name', 100);
            $table->unsignedBigInteger('min_points')->default(0);
            $table->string('color', 16)->default('#888888');
            $table->string('badge_icon', 32)->nullable();
            $table->json('perms')->nullable();
            $table->text('benefits')->nullable();
            $table->timestamps();

            $table->unique(['tenant_id', 'level']);
            $table->index(['tenant_id', 'min_points']);
        });
    }

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