<?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::table('manufacturing_boms', function (Blueprint $table) {
            // Add finished goods fields
            $table->foreignId('finished_goods_account_id')->nullable()->constrained('accounts')->restrictOnDelete();
            $table->decimal('basic_unit_amount', 15, 4)->nullable(); // e.g., 90 for a coil of cable
            $table->string('basic_unit')->nullable(); // e.g., 'meters', 'pieces', etc.
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('manufacturing_boms', function (Blueprint $table) {
            $table->dropForeign(['finished_goods_account_id']);
            $table->dropColumn(['finished_goods_account_id', 'basic_unit_amount', 'basic_unit']);
        });
    }
};
