<?php

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

/**
 * Batch tracking master switch.
 *
 * - is_batch_tracked = 1: product tracks individual batches/lots with specific
 *   manufacture/expiry dates and batch-specific pricing (legacy behaviour for
 *   every product).
 * - is_batch_tracked = 0: product is a single unified pool — no batch numbers,
 *   manufacture/expiry prompts, or lot picker. GRN overwrites the active unit
 *   price to the latest receipt price.
 *
 * The per-product expiry switch (is_expiry_tracked) is only meaningful when
 * is_batch_tracked is on; the UI hides and ignores it otherwise.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('products', function (Blueprint $table) {
            $table->boolean('is_batch_tracked')->default(false)->after('is_active');
        });
    }

    public function down(): void
    {
        Schema::table('products', function (Blueprint $table) {
            $table->dropColumn('is_batch_tracked');
        });
    }
};
