<?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('faction_rankings', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('faction_id')->unique();
            $table->string('faction_name');
            $table->unsignedTinyInteger('level')->default(0);
            $table->unsignedInteger('member_count')->default(0);
            $table->string('master_name')->nullable();
            $table->unsignedBigInteger('master_role_id')->nullable();
            $table->string('announce')->nullable();
            $table->timestamp('last_update')->nullable();
            $table->timestamps();
            
            $table->index(['level', 'member_count']);
            $table->index('faction_name');
        });
    }

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