use rust_decimal::Decimal;

#[derive(Debug, Clone, PartialEq, Default)]
pub struct TradeDetail {
    target_price: Option<Decimal>,
    target_amount: Option<Decimal>,
    confidence: Decimal,
}

impl TradeDetail {
    pub fn new(
        target_price: Option<Decimal>,
        target_amount: Option<Decimal>,
        confidence: Decimal,
    ) -> Self {
        Self {
            target_price,
            target_amount,
            confidence,
        }
    }

    pub fn target_price(&self) -> Option<Decimal> {
        self.target_price
    }

    pub fn target_amount(&self) -> Option<Decimal> {
        self.target_amount
    }

    pub fn confidence(&self) -> Decimal {
        self.confidence
    }
}

#[derive(Debug, Clone, PartialEq)]
pub enum TradeAction {
    BuyOpen(TradeDetail),
    BuyClose,
    SellOpen(TradeDetail),
    SellClose,
    Rebalance,
    None,
}

impl TradeAction {
    pub fn is_open(&self) -> bool {
        matches!(self, TradeAction::BuyOpen(_) | TradeAction::SellOpen(_))
    }

    pub fn is_buy(&self) -> bool {
        matches!(self, TradeAction::BuyOpen(_) | TradeAction::BuyClose)
    }

    pub fn is_sell(&self) -> bool {
        matches!(self, TradeAction::SellOpen(_) | TradeAction::SellClose)
    }

    pub fn target_price(&self) -> Option<Decimal> {
        match self {
            TradeAction::BuyOpen(detail) => detail.target_price,
            TradeAction::SellOpen(detail) => detail.target_price,
            _ => None,
        }
    }
}
