<?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
    {
        if (!Schema::hasTable('loyalty_levels')) {
            Schema::create('loyalty_levels', function (Blueprint $table) {
                $table->id();
                $table->string('name');
                $table->string('slug')->unique();
                $table->integer('min_points')->default(0);
                $table->decimal('discount_percent', 5, 2)->default(0)->comment('Pourcentage de réduction');
                $table->string('icon')->nullable();
                $table->string('color')->nullable();
                $table->text('benefits')->nullable()->comment('Avantages supplémentaires en JSON');
                $table->integer('sort_order')->default(0);
                $table->boolean('is_active')->default(true);
                $table->timestamps();
                
                $table->index('min_points');
                $table->index('sort_order');
            });
        }
    }

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