domainforge_core/primitives/
role.rs1use crate::ConceptId;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4use std::collections::HashMap;
5
6#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8pub struct Role {
9 id: ConceptId,
10 name: String,
11 namespace: String,
12 attributes: HashMap<String, Value>,
13}
14
15impl Role {
16 pub fn new_with_namespace(name: impl Into<String>, namespace: impl Into<String>) -> Self {
18 let namespace = namespace.into();
19 let name = name.into();
20 let id = ConceptId::from_concept(&namespace, &name);
21
22 Self {
23 id,
24 name,
25 namespace,
26 attributes: HashMap::new(),
27 }
28 }
29
30 pub fn id(&self) -> &ConceptId {
31 &self.id
32 }
33
34 pub fn name(&self) -> &str {
35 &self.name
36 }
37
38 pub fn namespace(&self) -> &str {
39 &self.namespace
40 }
41
42 pub fn attributes(&self) -> &HashMap<String, Value> {
43 &self.attributes
44 }
45
46 pub fn set_attribute(&mut self, key: impl Into<String>, value: Value) {
47 self.attributes.insert(key.into(), value);
48 }
49}