<?php

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

/**
 * Flag a core ERP product as a banquet "asset product" (1.9). Surfaced as a
 * checkbox on the product add/edit screen via the BMS module's product-form
 * hooks; asset-flagged products become selectable when building asset-type
 * package items. Additive column on the core products table — no core edits.
 */
return new class extends Migration {
    public function up(): void
    {
        if (Schema::hasTable('products') && ! Schema::hasColumn('products', 'bms_is_asset')) {
            Schema::table('products', function (Blueprint $t) {
                $t->boolean('bms_is_asset')->default(false)->after('not_for_selling');
            });
        }
    }

    public function down(): void
    {
        if (Schema::hasTable('products') && Schema::hasColumn('products', 'bms_is_asset')) {
            Schema::table('products', function (Blueprint $t) {
                $t->dropColumn('bms_is_asset');
            });
        }
    }
};
