use crate::entities::dive::structure::Dive;
use super::structure::RepetitionGroup;
const MISSING_REPETITION_GROUP_ID: &str = "Repetition group ID is required";
pub struct RepetitionGroupBuilder {
id: Option<String>,
dives: Vec<Dive>,
}
impl RepetitionGroupBuilder {
pub fn new() -> Self {
RepetitionGroupBuilder {
id: None,
dives: Vec::new(),
}
}
pub fn id(mut self, id: String) -> Self {
self.id = Some(id);
self
}
pub fn add_dive(mut self, dive: Dive) -> Self {
self.dives.push(dive);
self
}
pub fn build(self) -> Result<RepetitionGroup, &'static str> {
Ok(RepetitionGroup {
id: self.id.ok_or(MISSING_REPETITION_GROUP_ID)?,
dives: self.dives,
})
}
}
impl Default for RepetitionGroupBuilder {
fn default() -> Self {
Self::new()
}
}