<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('pw_shop_logs', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('shop_item_id');
            $table->unsignedInteger('user_id'); // Match users table ID type
            $table->integer('quantity');
            $table->bigInteger('total_price');
            $table->json('item_data')->nullable(); // Snapshot of item at purchase time
            $table->timestamps();

            $table->foreign('shop_item_id')->references('id')->on('pw_shop')->onDelete('cascade');
            // Note: Not adding FK to users since it uses a different ID type (game database)
            $table->index('shop_item_id');
            $table->index('user_id');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('pw_shop_logs');
    }
};
