use rust_decimal::Decimal;
use crate::types::{Currency, Period};
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Rate {
units_per_gbp: Decimal,
currency: Currency,
period: Period,
}
impl Rate {
pub(crate) fn new(units_per_gbp: Decimal, currency: Currency, period: Period) -> Rate {
Rate {
units_per_gbp,
currency,
period,
}
}
pub fn units_per_gbp(&self) -> Decimal {
self.units_per_gbp
}
pub fn to_gbp(&self, amount: Decimal) -> Decimal {
amount / self.units_per_gbp
}
pub fn from_gbp(&self, gbp: Decimal) -> Decimal {
gbp * self.units_per_gbp
}
pub fn currency(&self) -> Currency {
self.currency
}
pub fn period(&self) -> Period {
self.period
}
}