<?php

/**
 * 文件功能：百家乐买单活动主表迁移
 *
 * 保存每一次“你玩游戏我买单”活动的完整档案，
 * 包括开启人、开始时间、结束时间、领取截止时间与最终补偿发放总额。
 */

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

return new class extends Migration
{
    /**
     * 创建 baccarat_loss_cover_events 表。
     */
    public function up(): void
    {
        Schema::create('baccarat_loss_cover_events', function (Blueprint $table) {
            $table->id();
            $table->string('title', 100)->comment('活动标题');
            $table->string('description', 500)->nullable()->comment('活动说明');
            $table->enum('status', ['scheduled', 'active', 'settlement_pending', 'claimable', 'completed', 'cancelled'])
                ->default('scheduled')
                ->comment('活动状态');
            $table->dateTime('starts_at')->comment('活动开始时间');
            $table->dateTime('ends_at')->comment('活动结束时间');
            $table->dateTime('claim_deadline_at')->comment('补偿领取截止时间');
            $table->foreignId('created_by_user_id')
                ->nullable()
                ->constrained('users')
                ->nullOnDelete()
                ->comment('开启人');
            $table->foreignId('closed_by_user_id')
                ->nullable()
                ->constrained('users')
                ->nullOnDelete()
                ->comment('结束人');
            $table->timestamp('started_notice_sent_at')->nullable()->comment('开始通知发送时间');
            $table->timestamp('ended_notice_sent_at')->nullable()->comment('结束通知发送时间');
            $table->unsignedInteger('participant_count')->default(0)->comment('参与人数');
            $table->unsignedInteger('compensable_user_count')->default(0)->comment('可领取补偿人数');
            $table->unsignedBigInteger('total_loss_amount')->default(0)->comment('活动内用户总输金币');
            $table->unsignedBigInteger('total_claimed_amount')->default(0)->comment('最终已补偿发放金币');
            $table->timestamps();

            $table->index(['status', 'starts_at'], 'blce_status_starts_idx');
            $table->index(['starts_at', 'ends_at'], 'blce_window_idx');
        });
    }

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