<?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
    {
        if (Schema::hasColumn('trades', 'gross_payout')) {
            return;
        }

        Schema::table('trades', function (Blueprint $table) {
            $table->decimal('gross_payout', 20, 8)->nullable()->after('closed_at');
            $table->decimal('fees', 20, 8)->default(0)->after('gross_payout');
            $table->decimal('net_pnl', 20, 8)->nullable()->after('fees');
            $table->decimal('balance_before', 20, 8)->nullable()->after('net_pnl');
            $table->decimal('balance_after', 20, 8)->nullable()->after('balance_before');
            $table->decimal('tick_price', 20, 8)->nullable()->after('balance_after');
        });
    }

    public function down(): void
    {
        if (! Schema::hasColumn('trades', 'gross_payout')) {
            return;
        }

        Schema::table('trades', function (Blueprint $table) {
            $table->dropColumn([
                'gross_payout',
                'fees',
                'net_pnl',
                'balance_before',
                'balance_after',
                'tick_price',
            ]);
        });
    }
};
