<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('rank_histories', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
            $table->foreignId('from_rank_id')->nullable()->constrained('ranks')->nullOnDelete();
            $table->foreignId('to_rank_id')->nullable()->constrained('ranks')->nullOnDelete();
            $table->string('transition_type', 30)->default('unchanged')->index();
            $table->decimal('weak_leg_bv', 14, 2)->default(0);
            $table->decimal('team_turnover', 14, 2)->default(0);
            $table->unsignedInteger('active_directs')->default(0);
            $table->date('run_date')->index();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('rank_histories');
    }
};
