<?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
    {
        // Update BOMs table - just add is_active if missing
        Schema::table('boms', function (Blueprint $table) {
            if (!Schema::hasColumn('boms', 'is_active')) {
                $table->boolean('is_active')->default(true)->after('version');
            }
        });

        // Update BOM items table - just add scrap_pct if missing
        Schema::table('bom_items', function (Blueprint $table) {
            if (!Schema::hasColumn('bom_items', 'scrap_pct')) {
                $table->decimal('scrap_pct', 5, 2)->default(0)->after('quantity');
            }
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('bom_items', function (Blueprint $table) {
            if (Schema::hasColumn('bom_items', 'scrap_pct')) {
                $table->dropColumn('scrap_pct');
            }
        });

        Schema::table('boms', function (Blueprint $table) {
            if (Schema::hasColumn('boms', 'is_active')) {
                $table->dropColumn('is_active');
            }
        });
    }
};
