Skip to main content

cimstructs/
Season.rs

1/// A specified time period of the year.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct Season {
4    #[serde(flatten)]
5    pub base: super::IdentifiedObject,
6    /// Date season ends.
7    pub end_date: String,
8    /// Date season starts.
9    pub start_date: String,
10}
11impl crate::base::CimElement for Season {
12    fn mrid(&self) -> &str { &self.base.id }
13    fn type_name(&self) -> &'static str { "Season" }
14    fn as_any(&self) -> &dyn std::any::Any { self }
15    fn to_json_value(&self) -> serde_json::Value {
16        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
17    }
18    fn to_block(&self) -> crate::base::RdfBlock {
19        let mut block = self.base.to_block();
20        block.type_name = "Season".to_string();
21        if !self.end_date.is_empty() {
22            block.fields.insert("Season.endDate".into(), crate::base::FieldValue::Text(self.end_date.clone()));
23        }
24        if !self.start_date.is_empty() {
25            block.fields.insert("Season.startDate".into(), crate::base::FieldValue::Text(self.start_date.clone()));
26        }
27        block
28    }
29}
30
31impl Season {
32    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
33        let mut obj = Self::default();
34        obj.base.id.clone_from(&b.mrid);
35        for (key, val) in &b.fields {
36            match key.as_str() {
37                "Season.endDate" => {
38                    match val {
39                        crate::base::FieldValue::Text(sv) => { obj.end_date = sv.clone(); }
40                        crate::base::FieldValue::TextList(svs) => {
41                            if let Some(sv) = svs.last() { obj.end_date = sv.clone(); }
42                        }
43                        _ => {}
44                    }
45                }
46                "Season.startDate" => {
47                    match val {
48                        crate::base::FieldValue::Text(sv) => { obj.start_date = sv.clone(); }
49                        crate::base::FieldValue::TextList(svs) => {
50                            if let Some(sv) = svs.last() { obj.start_date = sv.clone(); }
51                        }
52                        _ => {}
53                    }
54                }
55                "IdentifiedObject.description" => {
56                    match val {
57                        crate::base::FieldValue::Text(sv) => { obj.base.description = sv.clone(); }
58                        crate::base::FieldValue::TextList(svs) => {
59                            if let Some(sv) = svs.last() { obj.base.description = sv.clone(); }
60                        }
61                        _ => {}
62                    }
63                }
64                "IdentifiedObject.energyIdentCodeEic" => {
65                    match val {
66                        crate::base::FieldValue::Text(sv) => { obj.base.energy_ident_code_eic = sv.clone(); }
67                        crate::base::FieldValue::TextList(svs) => {
68                            if let Some(sv) = svs.last() { obj.base.energy_ident_code_eic = sv.clone(); }
69                        }
70                        _ => {}
71                    }
72                }
73                "IdentifiedObject.mRID" => {
74                    match val {
75                        crate::base::FieldValue::Text(sv) => { obj.base.m_rid = sv.clone(); }
76                        crate::base::FieldValue::TextList(svs) => {
77                            if let Some(sv) = svs.last() { obj.base.m_rid = sv.clone(); }
78                        }
79                        _ => {}
80                    }
81                }
82                "IdentifiedObject.name" => {
83                    match val {
84                        crate::base::FieldValue::Text(sv) => { obj.base.name = sv.clone(); }
85                        crate::base::FieldValue::TextList(svs) => {
86                            if let Some(sv) = svs.last() { obj.base.name = sv.clone(); }
87                        }
88                        _ => {}
89                    }
90                }
91                "IdentifiedObject.shortName" => {
92                    match val {
93                        crate::base::FieldValue::Text(sv) => { obj.base.short_name = sv.clone(); }
94                        crate::base::FieldValue::TextList(svs) => {
95                            if let Some(sv) = svs.last() { obj.base.short_name = sv.clone(); }
96                        }
97                        _ => {}
98                    }
99                }
100                _ => {}
101            }
102        }
103        obj
104    }
105}