<?php

declare(strict_types=1);

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('market_packages', function (Blueprint $table) {
            $table->id();
            $table->string('item_key', 190);
            $table->string('item_type', 20); // plugin / theme
            $table->string('title', 255);
            $table->unsignedBigInteger('price'); // 单位：分
            $table->string('status', 20)->default('pending'); // pending / paid
            $table->foreignId('payment_id')->nullable()->constrained()->nullOnDelete();
            $table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
            $table->timestamps();

            $table->unique(['item_key', 'item_type']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('market_packages');
    }
};
