oca_bundle_semantics/state/oca/overlay/
entry_code_mapping.rs

1use crate::state::{attribute::Attribute, oca::Overlay};
2use oca_ast_semantics::ast::OverlayType;
3use said::derivation::HashFunctionCode;
4use said::{sad::SerializationFormats, sad::SAD};
5use serde::{Deserialize, Serialize};
6use std::any::Any;
7use std::collections::BTreeMap;
8
9#[derive(SAD, Serialize, Deserialize, Debug, Clone)]
10pub struct EntryCodeMappingOverlay {
11    #[said]
12    #[serde(rename = "d")]
13    said: Option<said::SelfAddressingIdentifier>,
14    capture_base: Option<said::SelfAddressingIdentifier>,
15    #[serde(rename = "type")]
16    overlay_type: OverlayType,
17    pub attribute_entry_codes_mapping: BTreeMap<String, Vec<String>>,
18}
19
20impl Overlay for EntryCodeMappingOverlay {
21    fn as_any(&self) -> &dyn Any {
22        self
23    }
24    fn capture_base(&self) -> &Option<said::SelfAddressingIdentifier> {
25        &self.capture_base
26    }
27    fn set_capture_base(&mut self, said: &said::SelfAddressingIdentifier) {
28        self.capture_base = Some(said.clone());
29    }
30    fn said(&self) -> &Option<said::SelfAddressingIdentifier> {
31        &self.said
32    }
33    fn overlay_type(&self) -> &OverlayType {
34        &self.overlay_type
35    }
36    fn attributes(&self) -> Vec<&String> {
37        self.attribute_entry_codes_mapping
38            .keys()
39            .collect::<Vec<&String>>()
40    }
41
42    fn add(&mut self, attribute: &Attribute) {
43        if attribute.entry_codes_mapping.is_some() {
44            self.attribute_entry_codes_mapping.insert(
45                attribute.name.clone(),
46                attribute.entry_codes_mapping.as_ref().unwrap().clone(),
47            );
48        }
49    }
50}
51impl EntryCodeMappingOverlay {
52    pub fn new() -> Box<Self> {
53        let overlay_version = "1.1".to_string();
54        Box::new(Self {
55            capture_base: None,
56            said: None,
57            overlay_type: OverlayType::EntryCodeMapping(overlay_version),
58            attribute_entry_codes_mapping: BTreeMap::new(),
59        })
60    }
61}