<?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('sub_categories', function (Blueprint $table) {
            // Form-prefill only (see docs/variant-and-multi-business-implementation-plan.md A6) —
            // never read by stock, pricing, or conversion logic.
            $table->foreignId('default_base_unit_id')->nullable()->after('sort_code')->constrained('unit_of_measures')->nullOnDelete();
        });
    }

    public function down(): void
    {
        Schema::table('sub_categories', function (Blueprint $table) {
            $table->dropForeign(['default_base_unit_id']);
            $table->dropColumn('default_base_unit_id');
        });
    }
};
