<?php

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

/**
 * Add-on package items (1.9.3) need a client-facing sale price distinct from
 * the internal unit_cost. Defaults from the linked product's selling price in
 * the builder; null for base inclusions.
 */
return new class extends Migration {
    public function up(): void
    {
        Schema::table('bms_package_items', function (Blueprint $t) {
            if (! Schema::hasColumn('bms_package_items', 'addon_price')) {
                $t->decimal('addon_price', 12, 2)->nullable()->after('unit_cost');
            }
        });
    }

    public function down(): void
    {
        Schema::table('bms_package_items', function (Blueprint $t) {
            if (Schema::hasColumn('bms_package_items', 'addon_price')) {
                $t->dropColumn('addon_price');
            }
        });
    }
};
