use crate::model::activity::ActivityId;
use crate::model::interval::Interval;
use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct GroupId(pub u32);
impl fmt::Display for GroupId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "g{}", self.0)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Group {
id: GroupId,
name: String,
shared_interval: Interval,
member_activities: Vec<ActivityId>,
}
impl Group {
pub fn new(id: GroupId, name: impl Into<String>, shared_interval: Interval) -> Self {
Self {
id,
name: name.into(),
shared_interval,
member_activities: Vec::new(),
}
}
pub fn add_member(&mut self, activity_id: ActivityId) {
self.member_activities.push(activity_id);
}
#[inline]
pub fn id(&self) -> GroupId {
self.id
}
#[inline]
pub fn name(&self) -> &str {
&self.name
}
#[inline]
pub fn shared_interval(&self) -> &Interval {
&self.shared_interval
}
#[inline]
pub fn member_activities(&self) -> &[ActivityId] {
&self.member_activities
}
}