<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('jackpot_pool_adjustments', function (Blueprint $table): void {
            $table->id();
            $table->string('adjustment_no', 32)->unique();
            $table->foreignId('jackpot_pool_id')->constrained('jackpot_pools')->cascadeOnDelete();
            $table->foreignId('admin_user_id')->constrained('admin_users')->cascadeOnDelete();
            $table->bigInteger('amount_delta')->comment('signed minor units; + increase pool');
            $table->bigInteger('balance_before');
            $table->bigInteger('balance_after');
            $table->string('reason', 500);
            $table->timestamps();

            $table->index(['jackpot_pool_id', 'created_at'], 'idx_jackpot_pool_adjustments_pool_created');
        });
    }

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