<?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('trades', function (Blueprint $table): void {
            $table->string('emotion')->nullable()->after('notes');
            $table->string('trading_session')->nullable()->after('emotion');
            $table->boolean('followed_risk_reward')->default(false)->after('trading_session');
            $table->boolean('avoided_overtrading')->default(false)->after('followed_risk_reward');
            $table->text('psychology_note')->nullable()->after('avoided_overtrading');
        });

        Schema::table('users', function (Blueprint $table): void {
            $table->string('public_username')->nullable()->unique()->after('referral_code');
            $table->boolean('public_profile_enabled')->default(false)->after('public_username');
            $table->boolean('show_public_profit')->default(false)->after('public_profile_enabled');
        });
    }

    public function down(): void
    {
        Schema::table('users', function (Blueprint $table): void {
            $table->dropUnique(['public_username']);
            $table->dropColumn(['public_username', 'public_profile_enabled', 'show_public_profit']);
        });

        Schema::table('trades', function (Blueprint $table): void {
            $table->dropColumn([
                'emotion',
                'trading_session',
                'followed_risk_reward',
                'avoided_overtrading',
                'psychology_note',
            ]);
        });
    }
};
