#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
pub struct Season {
#[serde(flatten)]
pub base: super::IdentifiedObject,
pub end_date: String,
pub start_date: String,
}
impl crate::base::CimElement for Season {
fn mrid(&self) -> &str { &self.base.id }
fn type_name(&self) -> &'static str { "Season" }
fn as_any(&self) -> &dyn std::any::Any { self }
fn to_json_value(&self) -> serde_json::Value {
serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
}
fn to_block(&self) -> crate::base::RdfBlock {
let mut block = self.base.to_block();
block.type_name = "Season".to_string();
if !self.end_date.is_empty() {
block.fields.insert("Season.endDate".into(), crate::base::FieldValue::Text(self.end_date.clone()));
}
if !self.start_date.is_empty() {
block.fields.insert("Season.startDate".into(), crate::base::FieldValue::Text(self.start_date.clone()));
}
block
}
}
impl Season {
pub fn from_block(b: &crate::base::RdfBlock) -> Self {
let mut obj = Self::default();
obj.base.id.clone_from(&b.mrid);
for (key, val) in &b.fields {
match key.as_str() {
"Season.endDate" => {
match val {
crate::base::FieldValue::Text(sv) => { obj.end_date = sv.clone(); }
crate::base::FieldValue::TextList(svs) => {
if let Some(sv) = svs.last() { obj.end_date = sv.clone(); }
}
_ => {}
}
}
"Season.startDate" => {
match val {
crate::base::FieldValue::Text(sv) => { obj.start_date = sv.clone(); }
crate::base::FieldValue::TextList(svs) => {
if let Some(sv) = svs.last() { obj.start_date = sv.clone(); }
}
_ => {}
}
}
"IdentifiedObject.description" => {
match val {
crate::base::FieldValue::Text(sv) => { obj.base.description = sv.clone(); }
crate::base::FieldValue::TextList(svs) => {
if let Some(sv) = svs.last() { obj.base.description = sv.clone(); }
}
_ => {}
}
}
"IdentifiedObject.energyIdentCodeEic" => {
match val {
crate::base::FieldValue::Text(sv) => { obj.base.energy_ident_code_eic = sv.clone(); }
crate::base::FieldValue::TextList(svs) => {
if let Some(sv) = svs.last() { obj.base.energy_ident_code_eic = sv.clone(); }
}
_ => {}
}
}
"IdentifiedObject.mRID" => {
match val {
crate::base::FieldValue::Text(sv) => { obj.base.m_rid = sv.clone(); }
crate::base::FieldValue::TextList(svs) => {
if let Some(sv) = svs.last() { obj.base.m_rid = sv.clone(); }
}
_ => {}
}
}
"IdentifiedObject.name" => {
match val {
crate::base::FieldValue::Text(sv) => { obj.base.name = sv.clone(); }
crate::base::FieldValue::TextList(svs) => {
if let Some(sv) = svs.last() { obj.base.name = sv.clone(); }
}
_ => {}
}
}
"IdentifiedObject.shortName" => {
match val {
crate::base::FieldValue::Text(sv) => { obj.base.short_name = sv.clone(); }
crate::base::FieldValue::TextList(svs) => {
if let Some(sv) = svs.last() { obj.base.short_name = sv.clone(); }
}
_ => {}
}
}
_ => {}
}
}
obj
}
}