#![allow(
    clippy::assertions_on_constants,
    clippy::assertions_on_result_states,
    clippy::clone_on_copy,
    clippy::decimal_literal_representation,
    clippy::doc_markdown,
    clippy::empty_line_after_doc_comments,
    clippy::field_reassign_with_default,
    clippy::get_unwrap,
    clippy::identity_op,
    clippy::inconsistent_digit_grouping,
    clippy::indexing_slicing,
    clippy::integer_division,
    clippy::len_zero,
    clippy::let_underscore_must_use,
    clippy::manual_div_ceil,
    clippy::manual_let_else,
    clippy::manual_range_contains,
    clippy::modulo_arithmetic,
    clippy::needless_range_loop,
    clippy::non_ascii_literal,
    clippy::redundant_clone,
    clippy::shadow_reuse,
    clippy::shadow_same,
    clippy::shadow_unrelated,
    clippy::single_match_else,
    clippy::str_to_string,
    clippy::string_slice,
    clippy::tests_outside_test_module,
    clippy::too_many_lines,
    clippy::unnecessary_wraps,
    clippy::unseparated_literal_suffix,
    clippy::use_debug,
    clippy::useless_vec,
    clippy::wildcard_enum_match_arm,
    clippy::else_if_without_else,
    clippy::expect_used,
    clippy::missing_const_for_fn,
    clippy::similar_names,
    clippy::type_complexity,
    clippy::collapsible_else_if,
    clippy::doc_lazy_continuation,
    clippy::items_after_test_module,
    clippy::map_clone,
    clippy::multiple_unsafe_ops_per_block,
    clippy::unwrap_or_default,
    clippy::assign_op_pattern,
    clippy::needless_borrow,
    clippy::println_empty_string,
    clippy::unnecessary_cast,
    clippy::used_underscore_binding,
    clippy::create_dir,
    clippy::implicit_saturating_sub,
    clippy::exit,
    clippy::expect_fun_call,
    clippy::too_many_arguments,
    clippy::unnecessary_map_or,
    clippy::unwrap_used,
    dead_code,
    unused_imports,
    unused_variables,
    clippy::cloned_ref_to_slice_refs,
    clippy::neg_multiply,
    clippy::while_let_loop,
    clippy::bool_assert_comparison,
    clippy::excessive_precision,
    clippy::trivially_copy_pass_by_ref,
    clippy::op_ref,
    clippy::redundant_closure,
    clippy::unnecessary_lazy_evaluations,
    clippy::if_then_some_else_none,
    clippy::unnecessary_to_owned,
    clippy::single_component_path_imports,
)]
// Test to verify SELL action closes long positions correctly
use ml::dqn::portfolio_tracker::{PortfolioTracker, TradeAction};
use tracing::info;

#[test]
fn test_sell_closes_long_position() {
    let mut tracker = PortfolioTracker::with_default_spread(10_000.0);

    // Initial state
    assert_eq!(tracker.cash_balance(), 10_000.0);
    assert_eq!(tracker.current_position(), 0.0);

    // BUY 50 @ $100
    tracker.execute_trade(TradeAction::Buy(50.0), 100.0);
    info!(
        cash = tracker.cash_balance(),
        position = tracker.current_position(),
        "After BUY"
    );
    assert_eq!(tracker.current_position(), 50.0);
    assert_eq!(tracker.cash_balance(), 5_000.0); // 10,000 - 5,000

    // SELL 50 @ $50 (should close position)
    tracker.execute_trade(TradeAction::Sell(50.0), 50.0);

    let final_cash = tracker.cash_balance();
    let final_position = tracker.current_position();
    info!(
        cash = final_cash,
        position = final_position,
        "After SELL"
    );

    // Expected results:
    // Position should be closed (0)
    // Cash should be: 5,000 (remaining) + 50*50 (sale proceeds) = 7,500
    assert_eq!(
        final_position, 0.0,
        "Position should be closed, got {}",
        final_position
    );
    assert_eq!(
        final_cash, 7_500.0,
        "Cash should be 7,500 after closing position at loss, got {}",
        final_cash
    );
}
