<?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('manufacturing_bom_history_ingredients', function (Blueprint $table) {
            $table->id();
            $table->foreignId('manufacturing_bom_history_id')->constrained('manufacturing_bom_history', 'id', 'mbh_ingredients_history_fk')->cascadeOnDelete();
            $table->foreignId('ingredient_account_id')->constrained('accounts', 'id', 'mbh_ingredients_account_fk')->restrictOnDelete();
            $table->string('ingredient_name');
            $table->string('ingredient_sku');
            $table->decimal('quantity_required', 15, 4);
            $table->string('unit');
            $table->enum('wastage_type', ['percentage', 'absolute']);
            $table->decimal('wastage_value', 15, 4);
            $table->decimal('current_wap', 15, 4)->default(0);
            $table->decimal('required_qty', 15, 4);
            $table->timestamps();

            $table->index(['manufacturing_bom_history_id']);
            $table->index(['ingredient_account_id']);
        });
    }

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