<?php

/**
 * 文件功能：双色球奖池流水表迁移
 *
 * 透明记录每期奖池的每笔变动（售票入池、派奖扣除、滚存、系统注入）。
 *
 * @author  ChatRoom Laravel
 *
 * @version 1.0.0
 */

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

return new class extends Migration
{
    /**
     * 创建 lottery_pool_logs 表。
     */
    public function up(): void
    {
        Schema::create('lottery_pool_logs', function (Blueprint $table) {
            $table->id();

            $table->foreignId('issue_id')->constrained('lottery_issues')->cascadeOnDelete()->comment('关联期次 ID');

            // 变动金额（正数=增加，负数=减少）
            $table->bigInteger('change_amount')->comment('变动金额');

            // 变动原因：ticket_sale/carry_over/admin_inject/system_inject/payout/prize_4th/prize_5th
            $table->string('reason', 30)->comment('变动原因');

            // 变动后奖池余额快照
            $table->unsignedBigInteger('pool_after')->comment('变动后奖池金额');

            // 备注（可选，如：第X注购票、N等奖派奖等）
            $table->string('remark', 200)->nullable()->comment('备注');

            $table->timestamp('created_at')->useCurrent();

            $table->index(['issue_id', 'reason']);
        });
    }

    /**
     * 回滚迁移。
     */
    public function down(): void
    {
        Schema::dropIfExists('lottery_pool_logs');
    }
};
