use super::{ElementMetadata, ModelElement, Operation, Property};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Aspect {
pub metadata: ElementMetadata,
pub properties: Vec<Property>,
pub operations: Vec<Operation>,
pub events: Vec<super::Event>,
}
impl Aspect {
pub fn new(urn: String) -> Self {
Self {
metadata: ElementMetadata::new(urn),
properties: Vec::new(),
operations: Vec::new(),
events: Vec::new(),
}
}
pub fn properties(&self) -> &[Property] {
&self.properties
}
pub fn add_property(&mut self, property: Property) {
self.properties.push(property);
}
pub fn operations(&self) -> &[Operation] {
&self.operations
}
pub fn add_operation(&mut self, operation: Operation) {
self.operations.push(operation);
}
pub fn events(&self) -> &[super::Event] {
&self.events
}
pub fn add_event(&mut self, event: super::Event) {
self.events.push(event);
}
}
impl ModelElement for Aspect {
fn urn(&self) -> &str {
&self.metadata.urn
}
fn metadata(&self) -> &ElementMetadata {
&self.metadata
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_aspect_creation() {
let mut aspect = Aspect::new("urn:samm:org.example:1.0.0#TestAspect".to_string());
aspect
.metadata
.add_preferred_name("en".to_string(), "Test Aspect".to_string());
assert_eq!(aspect.name(), "TestAspect");
assert_eq!(aspect.properties().len(), 0);
assert_eq!(aspect.operations().len(), 0);
}
}