<?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('simbhpjenis', function (Blueprint $table) {
            if (!Schema::hasColumn('simbhpjenis', 'satuan_kecil')) {
                $table->string('satuan_kecil', 100)->nullable()->after('satuan');
            }
            if (!Schema::hasColumn('simbhpjenis', 'konversi_kecil')) {
                $table->integer('konversi_kecil')->default(1)->after('satuan_kecil');
            }
            if (!Schema::hasColumn('simbhpjenis', 'stok_minimum')) {
                $table->integer('stok_minimum')->default(0)->after('konversi_kecil');
            }
        });

        Schema::table('simbhpreport', function (Blueprint $table) {
            if (!Schema::hasColumn('simbhpreport', 'qty_base')) {
                $table->integer('qty_base')->nullable()->after('pengeluaran');
            }
            if (!Schema::hasColumn('simbhpreport', 'satuan_transaksi')) {
                $table->string('satuan_transaksi', 20)->nullable()->after('qty_base');
            }
        });
    }

    public function down(): void
    {
        Schema::table('simbhpreport', function (Blueprint $table) {
            if (Schema::hasColumn('simbhpreport', 'qty_base')) {
                $table->dropColumn('qty_base');
            }
            if (Schema::hasColumn('simbhpreport', 'satuan_transaksi')) {
                $table->dropColumn('satuan_transaksi');
            }
        });

        Schema::table('simbhpjenis', function (Blueprint $table) {
            if (Schema::hasColumn('simbhpjenis', 'satuan_kecil')) {
                $table->dropColumn('satuan_kecil');
            }
            if (Schema::hasColumn('simbhpjenis', 'konversi_kecil')) {
                $table->dropColumn('konversi_kecil');
            }
            if (Schema::hasColumn('simbhpjenis', 'stok_minimum')) {
                $table->dropColumn('stok_minimum');
            }
        });
    }
};
