//! Trading action enum shared across DQN, PPO, ensemble, and other ML modules.

use serde::{Deserialize, Serialize};

/// Trading actions available to the `DQN` agent
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum TradingAction {
    /// Buy signal
    Buy = 0,
    /// Sell signal
    Sell = 1,
    /// Hold/Do nothing
    Hold = 2,
}

impl TradingAction {
    /// Convert action to integer index
    pub fn to_int(self) -> u8 {
        self as u8
    }

    /// Convert integer index to action
    pub fn from_int(val: u8) -> Option<Self> {
        match val {
            0 => Some(TradingAction::Buy),
            1 => Some(TradingAction::Sell),
            2 => Some(TradingAction::Hold),
            _ => None,
        }
    }

    /// Get all possible actions
    pub fn all() -> [TradingAction; 3] {
        [TradingAction::Buy, TradingAction::Sell, TradingAction::Hold]
    }
}
