<?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('cost_center_histories', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('item_id')->comment('Account ID of finished goods from chart_of_account_id = 53');
            $table->unsignedBigInteger('user_id')->comment('Who performed the action');
            $table->timestamps();

            // Foreign key constraints
            $table->foreign('item_id')->references('id')->on('accounts')->onDelete('cascade');
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');

            // Indexes
            $table->index(['item_id', 'user_id']);
        });
    }

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