use rust_decimal::Decimal;

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

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

    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
    }

    pub fn tick_to_fill(&self) -> Option<u32> {
        self.tick_to_fill
    }
}

#[derive(Debug, Copy, Clone, PartialEq)]
pub enum TradeAction {
    BuyOpen(TradeDetail),
    BuyClose(TradeDetail),
    SellOpen(TradeDetail),
    SellClose(TradeDetail),
    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 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) => Some(detail.confidence),
            _ => None,
        }
    }

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