use chrono::{DateTime, Utc};
use rust_decimal::Decimal;
#[derive(Clone, Debug)]
pub(crate) struct GiftBasis {
pub fmv_per_unit: Decimal,
}
#[derive(Clone, Debug)]
pub(crate) struct Lot {
pub asset: String,
pub wallet: String,
pub quantity: Decimal,
pub cost_basis: Decimal,
pub acquired_at: DateTime<Utc>,
pub lot_id: u64,
pub gift: Option<GiftBasis>,
}
impl Lot {
pub fn cost_basis_per_unit(&self) -> Decimal {
self.cost_basis / self.quantity
}
}
#[cfg(test)]
mod tests {
use super::*;
use chrono::{TimeZone, Utc};
use rust_decimal_macros::dec;
#[test]
fn cost_basis_per_unit_divides() {
let lot = Lot {
asset: "btc".into(),
wallet: "w".into(),
quantity: dec!(2),
cost_basis: dec!(100),
acquired_at: Utc.with_ymd_and_hms(2021, 1, 1, 0, 0, 0).unwrap(),
lot_id: 1,
gift: None,
};
assert_eq!(lot.cost_basis_per_unit(), dec!(50));
}
}