<?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('items', function (Blueprint $table) {
            $table->id();
            $table->string('name')->index();
            $table->string('sku')->unique();
            $table->enum('type', ['raw_material', 'finished_product'])->index();
   $table->foreignId('item_category_id')
          ->nullable()
          ->constrained()   // auto → item_categories(id)
          ->nullOnDelete();           $table->string('unit_of_measure');
            $table->string('barcode')->nullable()->unique();
            $table->decimal('reorder_level', 20, 6)->nullable();
            // $table->boolean('expiry_date_tracking')->default(false);
            $table->string('status')->nullable()->index();
            $table->boolean('is_active')->default(true)->index();

            $table->timestamps();
            $table->index(['sku','item_category_id']);

        });
    }

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