use std::time::SystemTime;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ChangeStatistics {
pub index: Option<usize>,
pub adds: usize,
pub updates: usize,
pub removes: usize,
pub refreshes: usize,
pub moves: usize,
pub count: usize,
pub last_updated: SystemTime,
}
impl Default for ChangeStatistics {
fn default() -> Self {
Self::new(None, 0, 0, 0, 0, 0, 0)
}
}
impl ChangeStatistics {
pub fn new(index: Option<usize>, adds: usize, updates: usize, removes: usize, refreshes: usize, moves: usize, count: usize) -> Self {
Self { index, adds, updates, removes, refreshes, moves, count, last_updated: SystemTime::now() }
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct ChangeSummary {
index: Option<usize>,
pub latest: ChangeStatistics,
pub overall: ChangeStatistics,
}
impl ChangeSummary {
pub fn empty() -> Self {
Self::default()
}
pub fn new(index: Option<usize>, latest: ChangeStatistics, overall: ChangeStatistics) -> Self {
Self { index, latest, overall }
}
pub fn index(&self) -> Option<usize> {
self.index
}
pub(crate) fn next(&self, adds: usize, updates: usize, removes: usize, refreshes: usize, moves: usize, count: usize) -> Self {
let index = self.overall.index.map_or(0, |index| index + 1);
let overall = &self.overall;
let latest = ChangeStatistics::new(Some(index), adds, updates, removes, refreshes, moves, count);
let overall = ChangeStatistics::new(
Some(index),
overall.adds + adds,
overall.updates + updates,
overall.removes + removes,
overall.refreshes + refreshes,
overall.moves + moves,
overall.count + count,
);
Self::new(Some(index), latest, overall)
}
}