use iri_rfc3987::Iri;
use crate::{Component, Severity, ShaclRule, Target};
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(
deny_unknown_fields,
bound(
serialize = "Value: serde::Serialize, Count: serde::Serialize, Flags: serde::Serialize",
deserialize = "Value: serde::Deserialize<'de>, Count: serde::Deserialize<'de>, Flags: serde::Deserialize<'de>"
)
)]
pub struct NodeShape<Value = crate::DefaultTerm, Count = Value, Flags = Value> {
pub id: Value,
pub targets: Vec<Target<Value>>,
pub components: Vec<Component<Value, Count, Flags>>,
pub property_shapes: Vec<Value>,
pub deactivated: bool,
pub severity: Severity,
pub messages: Vec<Value>,
pub rules: Vec<ShaclRule<Value>>,
pub order: Option<Value>,
}
impl<Value, Count, Flags> NodeShape<Value, Count, Flags> {
#[must_use]
pub fn new(id: Value) -> Self {
Self {
id,
targets: Vec::new(),
components: Vec::new(),
property_shapes: Vec::new(),
deactivated: false,
severity: Severity::default(),
messages: Vec::new(),
rules: Vec::new(),
order: None,
}
}
#[must_use]
pub fn with_target(mut self, target: Target<Value>) -> Self {
self.targets.push(target);
self
}
#[must_use]
pub fn with_component(mut self, component: Component<Value, Count, Flags>) -> Self {
self.components.push(component);
self
}
#[must_use]
pub fn with_property_shape(mut self, shape: Value) -> Self {
self.property_shapes.push(shape);
self
}
#[must_use]
pub fn with_deactivated(mut self, deactivated: bool) -> Self {
self.deactivated = deactivated;
self
}
#[must_use]
pub fn with_severity(mut self, severity: Severity) -> Self {
self.severity = severity;
self
}
#[must_use]
pub fn with_message(mut self, message: Value) -> Self {
self.messages.push(message);
self
}
#[must_use]
pub fn with_order(mut self, order: Value) -> Self {
self.order = Some(order);
self
}
#[must_use]
pub fn with_rule(mut self, rule: ShaclRule<Value>) -> Self {
self.rules.push(rule);
self
}
pub fn target_class_iris(&self) -> impl Iterator<Item = &Iri<String>> + '_ {
self.targets.iter().filter_map(|target| match target {
Target::Class(iri) => Some(iri),
_ => None,
})
}
#[must_use]
pub fn property_count(&self) -> usize {
self.property_shapes.len()
}
}