use std::collections::{HashMap, HashSet};
use super::super::types::EntityKind;
#[derive(Debug, Clone, Default)]
pub struct IngestScope {
by_kind: HashMap<EntityKind, HashSet<String>>,
}
impl IngestScope {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn with_kind<I, S>(mut self, kind: EntityKind, ids: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.by_kind
.entry(kind)
.or_default()
.extend(ids.into_iter().map(Into::into));
self
}
#[must_use]
pub fn is_unscoped(&self) -> bool {
self.by_kind.is_empty()
}
#[must_use]
pub fn owns(&self, kind: EntityKind, id: &str) -> bool {
if self.is_unscoped() {
return true;
}
self.by_kind
.get(&kind)
.is_some_and(|owned| owned.contains(id))
}
}