<?php

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

/**
 * The final step of the lot-pricing migration (docs/migration-plan.md): drop
 * the product-level prices. They were kept around through the backfill
 * (000003) and the nullable switch (000004) only so the opening-lots
 * migration could read them; the lot now owns both the selling price and the
 * cost, and nothing may fall back to a product-level figure again.
 *
 * Runs last by design: the backfill must have already copied prices onto
 * opening lots, and this file sits after 000004 in the migration list.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('products', function (Blueprint $table) {
            $table->dropColumn(['sale_price', 'purchase_price']);
        });
    }

    public function down(): void
    {
        Schema::table('products', function (Blueprint $table) {
            $table->decimal('sale_price', 10, 2)->nullable()->after('vat_rate');
            $table->decimal('purchase_price', 10, 2)->nullable()->after('sale_price');
        });
    }
};
