<?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('leaderboards', function (Blueprint $table): void {
            $table->id();
            $table->string('type', 20);
            $table->unsignedBigInteger('entity_id');
            $table->decimal('score', 14, 2)->default(0);
            $table->string('period', 20);
            $table->timestamps();

            $table->unique(['type', 'period', 'entity_id']);
            $table->index(['type', 'period', 'score']);
        });
    }

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