<?php

/**
 * 文件功能：百家乐局次表迁移
 *
 * 每一局百家乐对应一条记录，存储骰子结果、局次状态、投注汇总等信息。
 */

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

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

            // 骰子结果（开奖后写入）
            $table->unsignedTinyInteger('dice1')->nullable()->comment('第一颗骰子点数');
            $table->unsignedTinyInteger('dice2')->nullable()->comment('第二颗骰子点数');
            $table->unsignedTinyInteger('dice3')->nullable()->comment('第三颗骰子点数');
            $table->unsignedTinyInteger('total_points')->nullable()->comment('骰子总点数');
            $table->enum('result', ['big', 'small', 'triple', 'kill'])->nullable()->comment('开奖结果');

            // 局次状态
            $table->enum('status', ['betting', 'settling', 'settled', 'cancelled'])->default('betting');

            // 时间
            $table->dateTime('bet_opens_at')->comment('下注开始时间');
            $table->dateTime('bet_closes_at')->comment('下注截止时间');
            $table->dateTime('settled_at')->nullable()->comment('结算完成时间');

            // 投注汇总统计
            $table->unsignedBigInteger('total_bet_big')->default(0)->comment('押大总额');
            $table->unsignedBigInteger('total_bet_small')->default(0)->comment('押小总额');
            $table->unsignedBigInteger('total_bet_triple')->default(0)->comment('押豹子总额');
            $table->unsignedBigInteger('total_payout')->default(0)->comment('总赔付额');
            $table->unsignedInteger('bet_count')->default(0)->comment('下注人次');

            $table->timestamps();

            $table->index('status');
            $table->index('bet_closes_at');
        });
    }

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