<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
     /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('items', function (Blueprint $table) {
            $table->id(); // Primary key
            $table->unsignedBigInteger('item_category_id'); // Foreign key to item_categories table
            $table->string('bar_code')->unique()->nullable(false); // Barcode field, unique and required
            $table->string('item_name')->nullable(false); // Item name field, required
            $table->double('re_order_level')->nullable(); // Re-order level field, optional
            $table->boolean('is_vat_item')->default(false); // Is VAT item checkbox, default false
            $table->boolean('is_sscl_item')->default(false); // Is SSCL item checkbox, default false
            $table->timestamps(); // Created_at and updated_at timestamps

            // Define foreign key constraint
            $table->foreign('item_category_id')
                  ->references('id')
                  ->on('item_categories')
                  ->onDelete('cascade'); // Cascade delete if the category is deleted
        });
    }

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