<?php

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

class CreateItemsTable extends Migration
{
    public function up()
    {
        Schema::create('items', function (Blueprint $table) {
            $table->id();
            $table->string('item_code')->unique();
            $table->string('item_name');
            $table->string('description')->nullable();
            $table->string('status')->default('Active');
            $table->string('type')->default('NonProduct');
            $table->string('category')->nullable();
            $table->string('brand')->nullable();
            $table->foreignId('base_unit_id')->nullable()->constrained('item_units')->nullOnDelete();
            $table->foreignId('kode_proses_id')->nullable()->constrained('kode_proses')->nullOnDelete();
            $table->foreignId('kode_group_id')->nullable()->constrained('kode_group')->nullOnDelete();
            $table->foreignId('kode_setelan_id')->nullable()->constrained('kode_setelan')->nullOnDelete();
            $table->foreignId('kode_setelan_id_2')->nullable()->constrained('kode_setelan')->nullOnDelete();
            $table->foreignId('kode_jenis_id')->nullable()->constrained('kode_jenis')->nullOnDelete();
            $table->foreignId('kode_jenis_id_2')->nullable()->constrained('kode_jenis')->nullOnDelete();
            $table->foreignId('kode_nama_id')->nullable()->constrained('kode_nama')->nullOnDelete();
            //$table->unsignedBigInteger('supplier_id')->nullable();
            $table->jsonb('supplier_ids')->nullable();
            $table->unsignedBigInteger('warehouse_id')->nullable();
            $table->unsignedBigInteger('department_id')->nullable();
            $table->string('keterangan')->nullable();
            $table->string('alias')->nullable();
            $table->boolean('is_tax')->default(true);
            $table->boolean('is_cukai')->default(false);
            $table->decimal('cukai_price',20,2)->nullable();
            $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
            $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamps();

            //$table->foreign('supplier_id')->references('id')->on('suppliers')->onDelete('restrict');
            // $table->foreign('warehouse_id')->references('id')->on('warehouse')->onDelete('restrict');
            // $table->foreign('department_id')->references('id')->on('department')->onDelete('restrict');
        });
    }

    public function down()
    {
        Schema::dropIfExists('items');
    }
}
