<?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('pw_ranking', function (Blueprint $table) {
            $table->id();
            $table->integer('role_id')->unique()->comment('Role ID from pw_pvp');
            $table->string('role_name')->comment('Role name');
            $table->integer('cls')->nullable()->default(0)->comment('Character class');
            $table->integer('kills')->default(0)->comment('Total kills');
            $table->integer('deaths')->default(0)->comment('Total deaths');
            $table->decimal('kd_ratio', 8, 2)->default(0)->comment('Kill/Death ratio');
            $table->timestamp('last_update')->useCurrent()->comment('Last update time');
            $table->timestamps();
            
            // Indexes for performance
            $table->index('role_id');
            $table->index('kills');
            $table->index('kd_ratio');
        });
    }

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