<?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('processing_penerimaan_bahan_details', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('penerimaan_bahan_id');
            $table->unsignedBigInteger('warehouse_id');
            $table->unsignedBigInteger('item_id');
            $table->decimal('qty', 25, 3);
            $table->unsignedBigInteger('unit');
            $table->decimal('base_qty', 20, 3);
            $table->string('created_by');
            $table->timestamp('created_at');
            $table->string('updated_by');
            $table->timestamp('updated_at');

            $table->foreign('penerimaan_bahan_id')->references('id')->on('processing_penerimaan_bahan')->onDelete('restrict');
            $table->foreign('warehouse_id')->references('id')->on('warehouse')->onDelete('restrict');
            $table->foreign('item_id')->references('id')->on('items')->onDelete('restrict');
            $table->foreign(['item_id','base_qty'])->references(['item_id','conversion'])->on('item_details')->onDelete('restrict');
        });
    }

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