<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('items', function (Blueprint $table) {
            $table->decimal('trade_price', 10, 2)->nullable()->default(null)->after('sale_price_exvat');
            $table->decimal('trade_price_exvat', 10, 2)->nullable()->default(null)->after('trade_price');
            $table->decimal('trade_sale_price', 10, 2)->nullable()->default(null)->after('trade_price_exvat');
            $table->decimal('trade_sale_price_exvat', 10, 2)->nullable()->default(null)->after('trade_sale_price');
            $table->index('trade_price');
        });

        Schema::table('items_sizes', function (Blueprint $table) {
            $table->decimal('trade_price', 10, 2)->nullable()->default(null)->after('sale_price_exvat');
            $table->decimal('trade_price_exvat', 10, 2)->nullable()->default(null)->after('trade_price');
            $table->decimal('trade_sale_price', 10, 2)->nullable()->default(null)->after('trade_price_exvat');
            $table->decimal('trade_sale_price_exvat', 10, 2)->nullable()->default(null)->after('trade_sale_price');
        });
    }

    public function down(): void
    {
        Schema::table('items', function (Blueprint $table) {
            $table->dropIndex(['trade_price']);
            $table->dropColumn(['trade_price', 'trade_price_exvat', 'trade_sale_price', 'trade_sale_price_exvat']);
        });

        Schema::table('items_sizes', function (Blueprint $table) {
            $table->dropColumn(['trade_price', 'trade_price_exvat', 'trade_sale_price', 'trade_sale_price_exvat']);
        });
    }
};
