use crate::model::interval::Interval;
use crate::model::resource::ResourceId;
use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ActivityId(pub u32);
impl fmt::Display for ActivityId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "a{}", self.0)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ResourceDemand {
pub resource_id: ResourceId,
pub demand: u32,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Activity {
id: ActivityId,
name: String,
interval: Interval,
demands: Vec<ResourceDemand>,
}
impl Activity {
pub fn new(id: ActivityId, name: impl Into<String>, interval: Interval) -> Self {
Self {
id,
name: name.into(),
interval,
demands: Vec::new(),
}
}
pub fn require_resource(&mut self, resource_id: ResourceId, demand: u32) {
self.demands.push(ResourceDemand {
resource_id,
demand,
});
}
#[inline]
pub fn id(&self) -> ActivityId {
self.id
}
#[inline]
pub fn name(&self) -> &str {
&self.name
}
#[inline]
pub fn interval(&self) -> &Interval {
&self.interval
}
#[inline]
pub fn demands(&self) -> &[ResourceDemand] {
&self.demands
}
}