<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('inventory_items', function (Blueprint $table) {
            if (!Schema::hasColumn('inventory_items', 'purchase_unit')) {
                $table->string('purchase_unit')->nullable()->after('unit');
            }
            if (!Schema::hasColumn('inventory_items', 'unit_conversion_factor')) {
                $table->decimal('unit_conversion_factor', 10, 3)->nullable()->after('purchase_unit');
            }
        });
    }

    public function down(): void
    {
        Schema::table('inventory_items', function (Blueprint $table) {
            if (Schema::hasColumn('inventory_items', 'unit_conversion_factor')) {
                $table->dropColumn('unit_conversion_factor');
            }
            if (Schema::hasColumn('inventory_items', 'purchase_unit')) {
                $table->dropColumn('purchase_unit');
            }
        });
    }
};
