<?php

/**
 * 文件功能：百家乐下注记录表迁移
 *
 * 记录每个用户在每局中的押注类型、金额和结算结果。
 */

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

return new class extends Migration
{
    /**
     * 创建 baccarat_bets 表。
     */
    public function up(): void
    {
        Schema::create('baccarat_bets', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('round_id')->comment('关联局次');
            $table->unsignedBigInteger('user_id')->comment('下注用户');
            $table->enum('bet_type', ['big', 'small', 'triple'])->comment('押注类型');
            $table->unsignedInteger('amount')->comment('押注金额');
            $table->unsignedInteger('payout')->default(0)->comment('赔付金额（含本金）');
            $table->enum('status', ['pending', 'won', 'lost', 'refunded'])->default('pending');
            $table->timestamps();

            $table->foreign('round_id')->references('id')->on('baccarat_rounds')->cascadeOnDelete();
            $table->index(['round_id', 'user_id']);
            $table->index(['user_id', 'status']);
            // 每局每人每种类型只能下一注（可在 Service 层控制）
        });
    }

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