use crate::backlog::{BacklogItem, ItemId};
use crate::error::{Error, Result};
pub(crate) fn validate_parent(
items: &[BacklogItem],
child: &ItemId,
parent: &ItemId,
) -> Result<()> {
if crate::backlog::parent_creates_cycle(items, child, parent) {
return Err(Error::ParentCycle {
child: child.clone(),
parent: parent.clone(),
});
}
if !items.iter().any(|item| &item.id == parent) {
return Err(Error::NotFound(parent.clone()));
}
Ok(())
}
pub(crate) fn validate_dependencies(
items: &[BacklogItem],
item: &ItemId,
dependencies: &[ItemId],
) -> Result<bool> {
let mut cycle_warning = false;
for dependency in dependencies {
if dependency != item && !items.iter().any(|current| ¤t.id == dependency) {
return Err(Error::NotFound(dependency.clone()));
}
cycle_warning |= crate::backlog::dependency_creates_cycle(items, item, dependency);
}
Ok(cycle_warning)
}