-- Tabela para armazenar trades dos usuários
CREATE TABLE IF NOT EXISTS user_trades (
    id INT AUTO_INCREMENT PRIMARY KEY,
    user_id INT NOT NULL,
    trade_type ENUM('buy', 'sell') NOT NULL,
    entry_candle_index INT NOT NULL,
    entry_round_number INT NOT NULL,
    entry_points DECIMAL(10,2) NOT NULL,
    entry_amount DECIMAL(10,2) NOT NULL,
    exit_candle_index INT NULL,
    exit_round_number INT NULL,
    exit_points DECIMAL(10,2) NULL,
    profit_loss DECIMAL(10,2) NULL,
    status ENUM('open', 'closed') DEFAULT 'open',
    candle_mode INT NOT NULL DEFAULT 2,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    closed_at TIMESTAMP NULL,
    FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
    INDEX idx_user_status (user_id, status),
    INDEX idx_round_number (entry_round_number)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
