use std::sync::Arc;
use rust_decimal::Decimal;
use super::Commodity;
#[derive(Debug, Eq)]
pub struct PriceEntry {
pub timestamp: jiff::Zoned,
pub base_commodity: Arc<Commodity>,
pub eq_amount: Decimal,
pub eq_commodity: Arc<Commodity>,
pub comments: Option<String>,
}
impl Ord for PriceEntry {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.timestamp
.cmp(&other.timestamp)
.then_with(|| self.base_commodity.cmp(&other.base_commodity))
.then_with(|| self.eq_commodity.cmp(&other.eq_commodity))
}
}
impl PartialEq for PriceEntry {
fn eq(&self, other: &Self) -> bool {
self.timestamp == other.timestamp
&& self.base_commodity == other.base_commodity
&& self.eq_commodity == other.eq_commodity
}
}
impl PartialOrd for PriceEntry {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
pub type PriceDb = Vec<PriceEntry>;