use crate::models::ActivityEntry;

pub const DEFAULT_ACTIVITY_LIMIT: usize = 200;

pub fn sort_activity_desc(mut entries: Vec<ActivityEntry>) -> Vec<ActivityEntry> {
    entries.sort_by(|left, right| right.at.cmp(&left.at).then_with(|| right.id.cmp(&left.id)));
    entries
}

pub fn cap_activity(entries: Vec<ActivityEntry>, limit: usize) -> Vec<ActivityEntry> {
    let mut entries = sort_activity_desc(entries);
    entries.truncate(limit);
    entries
}

pub fn append_activity(
    mut entries: Vec<ActivityEntry>,
    entry: ActivityEntry,
    limit: usize,
) -> Vec<ActivityEntry> {
    entries.push(entry);
    cap_activity(entries, limit)
}
