<?php

/**
 * 文件功能：节日福利领取记录表迁移
 *
 * 记录每个用户对每次节日福利活动的领取状态和金额。
 */

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

return new class extends Migration
{
    /**
     * 创建 holiday_claims 表。
     */
    public function up(): void
    {
        Schema::create('holiday_claims', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('event_id')->comment('关联活动 ID');
            $table->unsignedBigInteger('user_id')->comment('领取用户 ID');
            $table->unsignedInteger('amount')->comment('实际领取金额');
            $table->dateTime('claimed_at')->comment('领取时间');

            $table->foreign('event_id')->references('id')->on('holiday_events')->cascadeOnDelete();
            $table->unique(['event_id', 'user_id'], 'uq_holiday_event_user');
            $table->index('user_id');
        });
    }

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