<?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('broker_accounts', function (Blueprint $table) {
            $table->boolean('is_market_feed_provider')->default(false)->after('broker');
            $table->decimal('available_balance', 16, 2)->default(0)->after('last_synced_at');
            $table->decimal('margin_used', 16, 2)->default(0)->after('available_balance');
            $table->decimal('unrealized_pnl_total', 16, 2)->default(0)->after('margin_used');
            $table->decimal('realized_pnl_total', 16, 2)->default(0)->after('unrealized_pnl_total');
            $table->decimal('collateral', 16, 2)->nullable()->after('realized_pnl_total');
            $table->json('sync_snapshot')->nullable()->after('collateral');
        });
    }

    public function down(): void
    {
        Schema::table('broker_accounts', function (Blueprint $table) {
            $table->dropColumn([
                'is_market_feed_provider',
                'available_balance',
                'margin_used',
                'unrealized_pnl_total',
                'realized_pnl_total',
                'collateral',
                'sync_snapshot',
            ]);
        });
    }
};
