use crate::{impl_from_uint_for, OrderId};
use num_bigint::BigUint;
use serde::{Deserialize, Serialize};

pub mod meme_market;
pub mod spot_market;

/// Order side
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
pub enum OrderSide {
    /// Ask
    /// Note: Ask means sell base asset
    Ask = 1,

    /// Bid
    /// Note: Bid means buy base asset
    Bid = 2,
}

impl From<BigUint> for OrderSide {
    fn from(side: BigUint) -> Self {
        match side {
            side if side == BigUint::from(1u8) => OrderSide::Ask,
            side if side == BigUint::from(2u8) => OrderSide::Bid,
            _ => panic!("invalid order side"),
        }
    }
}

impl Into<BigUint> for OrderSide {
    fn into(self) -> BigUint {
        match self {
            OrderSide::Ask => BigUint::from(1u8),
            OrderSide::Bid => BigUint::from(2u8),
        }
    }
}

impl_from_uint_for!(OrderSide, u8, u16, u32, u64, u128);

/// Order scope
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
pub enum OrderScope {
    /// Exact order id
    Exact(OrderId),

    /// Side
    Side(OrderSide),

    /// All
    /// Note: all means all orders
    All,
}
