use rust_decimal::Decimal;

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

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

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

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

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

#[derive(Debug, Copy, Clone, PartialEq)]
pub enum TradeAction {
    BuyOpen(TradeDetail),
    BuyClose(TradeDetail),
    BuyHedge(TradeDetail),
    BuyTrim(TradeDetail),
    SellOpen(TradeDetail),
    SellClose(TradeDetail),
    SellHedge(TradeDetail),
    SellTrim(TradeDetail),
    None,
}

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

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

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

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

    pub fn confidence(&self) -> Option<Decimal> {
        match self {
            TradeAction::BuyOpen(detail)
            | TradeAction::SellOpen(detail)
            | TradeAction::BuyClose(detail)
            | TradeAction::SellClose(detail)
            | TradeAction::BuyTrim(detail)
            | TradeAction::SellTrim(detail)
            | TradeAction::BuyHedge(detail)
            | TradeAction::SellHedge(detail) => Some(detail.confidence),
            _ => None,
        }
    }
}
