use crate::types::{Money, OddsX10000};
use serde::{Deserialize, Serialize};
use std::fmt;

#[derive(
    Debug,
    Clone,
    Copy,
    Serialize,
    Deserialize,
    PartialEq,
    Eq,
    rkyv::Archive,
    rkyv::Serialize,
    rkyv::Deserialize,
)]
pub enum FillPrice {
    Odds(OddsX10000),
    Ticks(u16),
}

#[derive(
    Debug,
    Clone,
    Copy,
    Serialize,
    Deserialize,
    PartialEq,
    Eq,
    rkyv::Archive,
    rkyv::Serialize,
    rkyv::Deserialize,
)]
pub enum FillQuantity {
    Stake(Money),
    Shares(u64),
}

impl PartialEq<Money> for FillQuantity {
    fn eq(&self, other: &Money) -> bool {
        matches!(self, FillQuantity::Stake(m) if m == other)
    }
}

impl PartialEq<FillQuantity> for Money {
    fn eq(&self, other: &FillQuantity) -> bool {
        matches!(other, FillQuantity::Stake(m) if m == self)
    }
}

impl fmt::Display for FillPrice {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            FillPrice::Odds(v) => write!(f, "ODDS:{v}"),
            FillPrice::Ticks(v) => write!(f, "TICKS:{v}"),
        }
    }
}

impl fmt::Display for FillQuantity {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            FillQuantity::Stake(v) => write!(f, "STAKE:{v}"),
            FillQuantity::Shares(v) => write!(f, "SHARES:{v}"),
        }
    }
}
