<?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('item_exchange_log', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('user_id')->index()->comment('User ID from users table');
            $table->unsignedInteger('role_id')->index()->comment('Character/Role ID');
            $table->string('role_name', 64)->comment('Character name at time of exchange');
            $table->unsignedInteger('item_id')->comment('Game item ID');
            $table->unsignedInteger('item_count')->comment('Number of items exchanged');
            $table->unsignedInteger('gold_per_item')->comment('Gold amount per item');
            $table->unsignedInteger('gold_received')->comment('Total gold received');
            $table->timestamp('created_at')->useCurrent()->comment('Exchange timestamp');
            
            $table->index(['user_id', 'created_at']);
            $table->index(['role_id', 'created_at']);
            $table->index('item_id');
        });
    }

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