use crate::core::Bmc;
use crate::oem::lenovo::schema::lenovo_computer_system::LenovoSystemProperties as LenovoSystemPropertiesSchema;
use crate::schema::computer_system::ComputerSystem as ComputerSystemSchema;
use crate::Error;
use crate::NvBmc;
use std::convert::identity;
use std::marker::PhantomData;
use std::sync::Arc;
#[doc(inline)]
pub use crate::oem::lenovo::schema::lenovo_computer_system::FpMode;
#[doc(inline)]
pub use crate::oem::lenovo::schema::lenovo_computer_system::PortSwitchingTo;
pub struct LenovoComputerSystem<B: Bmc> {
data: Arc<LenovoSystemPropertiesSchema>,
_marker: PhantomData<B>,
}
impl<B: Bmc> LenovoComputerSystem<B> {
pub(crate) fn new(
_bmc: &NvBmc<B>,
computer_system: &ComputerSystemSchema,
) -> Result<Option<Self>, Error<B>> {
if let Some(oem) = computer_system
.base
.base
.oem
.as_ref()
.and_then(|oem| oem.additional_properties.get("Lenovo"))
{
let data = Arc::new(serde_json::from_value(oem.clone()).map_err(Error::Json)?);
Ok(Some(Self {
data,
_marker: PhantomData,
}))
} else {
Ok(None)
}
}
#[must_use]
pub fn raw(&self) -> Arc<LenovoSystemPropertiesSchema> {
self.data.clone()
}
pub fn front_panel_mode(&self) -> Option<FpMode> {
self.data
.usb_management_port_assignment
.as_ref()
.or_else(|| self.data.front_panel_usb.as_ref())
.and_then(Option::as_ref)
.and_then(|v| v.fp_mode)
.and_then(identity)
}
pub fn port_switching_to(&self) -> Option<PortSwitchingTo> {
self.data
.usb_management_port_assignment
.as_ref()
.or_else(|| self.data.front_panel_usb.as_ref())
.and_then(Option::as_ref)
.and_then(|v| v.port_switching_to)
.and_then(identity)
}
}