<?php

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

/**
 * Remove the supplier batch number end to end.
 *
 * A lot has exactly one identity now: the system-generated
 * `internal_batch_number` minted by DocumentNumberService on GRN confirm.
 * The supplier's own printed number was a parallel, optional, unvalidated
 * second identifier that nothing keyed on — it only ever travelled from the
 * GRN line (`grn_items.batch_number`) onto the lot and back out to a few
 * read-only labels, and having two "batch numbers" on screen was the source
 * of the confusion this removes.
 *
 * Both halves go together: `grn_items.batch_number` existed solely to feed
 * `stock_batches.supplier_batch_number` (see the comment in
 * 2026_07_02_000028), so keeping it would leave a write-only column and a
 * form field that lands nowhere.
 *
 * Destructive: historical supplier-side numbers on past receipts and lots are
 * dropped, not archived. down() restores the columns but not their data.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('stock_batches', function (Blueprint $table) {
            $table->dropColumn('supplier_batch_number');
        });

        Schema::table('grn_items', function (Blueprint $table) {
            $table->dropColumn('batch_number');
        });
    }

    public function down(): void
    {
        Schema::table('stock_batches', function (Blueprint $table) {
            $table->string('supplier_batch_number', 100)->nullable()->after('internal_batch_number');
        });

        Schema::table('grn_items', function (Blueprint $table) {
            $table->string('batch_number', 100)->nullable()->after('product_id');
        });
    }
};
