<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('inventories', function (Blueprint $table) {
            $table->decimal('unit_cost', 12, 4)->default(0)->after('quantity')->comment('單位成本');
            $table->decimal('total_value', 12, 4)->default(0)->after('unit_cost')->comment('庫存總價值');
        });

        Schema::table('inventory_transactions', function (Blueprint $table) {
            $table->decimal('unit_cost', 12, 4)->nullable()->after('quantity')->comment('異動當下的單位成本');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('inventory_transactions', function (Blueprint $table) {
            $table->dropColumn('unit_cost');
        });

        Schema::table('inventories', function (Blueprint $table) {
            $table->dropColumn(['unit_cost', 'total_value']);
        });
    }
};
