<?php

declare(strict_types=1);

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

return new class extends Migration
{
    public function up(): void
    {
        if (! Schema::hasTable('dberp_stocktake_order_items')
            || Schema::hasColumn('dberp_stocktake_order_items', 'serial_numbers')) {
            return;
        }

        Schema::table('dberp_stocktake_order_items', function (Blueprint $table): void {
            $table->json('serial_numbers')->nullable()->after('actual_quantity')->comment('实盘序列号快照');
        });
    }

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