<?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_issues 表。
     */
    public function up(): void
    {
        Schema::create('lottery_issues', function (Blueprint $table) {
            $table->id();

            // 期号，如 2026063（年份+当年第几期）
            $table->string('issue_no', 20)->unique()->comment('期号');

            // 状态：open=购票中 / closed=已停售 / settled=已开奖
            $table->string('status', 20)->default('open')->comment('状态');

            // 开奖号码（开奖后写入）
            $table->unsignedTinyInteger('red1')->nullable()->comment('开奖红球1');
            $table->unsignedTinyInteger('red2')->nullable()->comment('开奖红球2');
            $table->unsignedTinyInteger('red3')->nullable()->comment('开奖红球3');
            $table->unsignedTinyInteger('blue')->nullable()->comment('开奖蓝球');

            // 奖池金额
            $table->unsignedBigInteger('pool_amount')->default(0)->comment('本期奖池金额（含滚存）');
            $table->unsignedBigInteger('carry_amount')->default(0)->comment('从上期滚存来的金额');

            // 超级期标记
            $table->boolean('is_super_issue')->default(false)->comment('是否超级期');
            $table->unsignedTinyInteger('no_winner_streak')->default(0)->comment('截止本期连续无一等奖期数');

            // 统计
            $table->unsignedInteger('total_tickets')->default(0)->comment('本期购票总注数');
            $table->unsignedBigInteger('payout_amount')->default(0)->comment('实际派奖总额');

            // 时间
            $table->timestamp('sell_closes_at')->nullable()->comment('停售时间');
            $table->timestamp('draw_at')->nullable()->comment('开奖时间');
            $table->timestamps();

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

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