<?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
{
    /**
     * 创建 idiom_game_rounds 表。
     */
    public function up(): void
    {
        Schema::create('idiom_game_rounds', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('room_id')->comment('游戏所在房间 ID');
            $table->unsignedBigInteger('idiom_id')->comment('当前题目 ID');
            $table->string('status', 20)->default('pending')->comment('状态：pending/active/answered/ended');
            $table->integer('reward_gold')->default(0)->comment('答对奖励金币');
            $table->integer('reward_exp')->default(0)->comment('答对奖励经验');
            $table->unsignedBigInteger('winner_id')->nullable()->comment('答对用户 ID');
            $table->string('winner_username', 50)->nullable()->comment('答对用户名');
            $table->timestamp('started_at')->nullable()->comment('开始答题时间');
            $table->timestamp('ended_at')->nullable()->comment('结束答题时间');
            $table->timestamps();

            $table->foreign('idiom_id')->references('id')->on('idioms')->onDelete('cascade');
            $table->index('status');
        });
    }

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