<?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::table('inventories', function (Blueprint $table) {
            $table->foreignId('item_id')->nullable()->after('id')->constrained('items')->onDelete('cascade');
            $table->foreignId('category_id')->nullable()->after('item_id')->constrained('inventory_categories')->onDelete('cascade');
            $table->index('item_id');
            $table->index('category_id');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('inventories', function (Blueprint $table) {
            $table->dropForeign(['item_id']);
            $table->dropForeign(['category_id']);
            $table->dropColumn(['item_id', 'category_id']);
        });
    }
};
