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

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

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

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