<?php

/**
 * 文件功能：创建商店商品表（shop_items）
 * 存储商店内所有可购买的商品定义
 *
 * @package  Database\Migrations
 */

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::create('shop_items', function (Blueprint $table) {
            $table->id();
            $table->string('name', 50)->comment('商品名称');
            $table->string('slug', 50)->unique()->comment('商品唯一标识');
            $table->string('description', 255)->nullable()->comment('商品描述');
            $table->string('icon', 20)->default('🛍')->comment('商品图标 emoji');
            $table->unsignedInteger('price')->comment('价格（金币）');
            // type: instant=单次立即执行, duration=有时效, one_time=一次性道具
            $table->enum('type', ['instant', 'duration', 'one_time'])->comment('商品类型');
            $table->unsignedTinyInteger('duration_days')->nullable()->comment('有效天数（duration 类型用）');
            $table->unsignedTinyInteger('sort_order')->default(0)->comment('排序');
            $table->boolean('is_active')->default(true)->comment('是否上架');
            $table->timestamps();
        });
    }

    /**
     * 回滚迁移：删除商品表
     */
    public function down(): void
    {
        Schema::dropIfExists('shop_items');
    }
};
