<?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('m_raw_materials', function (Blueprint $table) {
            if (!Schema::hasColumn('m_raw_materials', 'conversion_factor')) {
                $table->decimal('conversion_factor', 8, 4)->default(1)->after('uom_pakai')
                    ->comment('Conversion factor from UOM to UOM Pakai (e.g., 1 KG = 1000 GR)');
            }
        });
    }

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