<?php

/**
 * 文件功能：为每日签到记录补充补签来源字段。
 *
 * 记录补签卡消耗的购买记录与补签时间，便于日历区分正常签到和补签。
 */

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

return new class extends Migration
{
    /**
     * 方法功能：新增补签标记、补签卡购买记录和补签完成时间。
     */
    public function up(): void
    {
        Schema::table('daily_sign_ins', function (Blueprint $table): void {
            $table->boolean('is_makeup')->default(false)->after('room_id')->comment('是否通过补签卡补签');
            $table->foreignId('makeup_purchase_id')->nullable()->after('is_makeup')->constrained('user_purchases')->nullOnDelete()->comment('消耗的补签卡购买记录ID');
            $table->timestamp('makeup_at')->nullable()->after('makeup_purchase_id')->comment('补签完成时间');
        });
    }

    /**
     * 方法功能：回滚补签字段。
     */
    public function down(): void
    {
        Schema::table('daily_sign_ins', function (Blueprint $table): void {
            $table->dropConstrainedForeignId('makeup_purchase_id');
            $table->dropColumn(['is_makeup', 'makeup_at']);
        });
    }
};
