use crate::mac_address::MacAddress;
use crate::oem::lenovo::schema::lenovo_port::Port as LenovoPortSchema;
use crate::schema::port::Port as PortSchema;
use serde_json::Error as JsonError;
use std::sync::Arc;
pub struct LenovoPort {
data: Arc<LenovoPortSchema>,
}
impl LenovoPort {
pub(crate) fn new(port: &PortSchema) -> Result<Option<Self>, JsonError> {
port.base
.base
.oem
.as_ref()
.and_then(|oem| oem.additional_properties.get("Lenovo"))
.map(|data| {
serde_json::from_value(data.clone()).map(|data| Self {
data: Arc::new(data),
})
})
.transpose()
}
#[must_use]
pub fn physical_port_mac_address(&self) -> Option<MacAddress<'_>> {
self.data
.physical_port_mac_address
.as_ref()
.and_then(Option::as_deref)
.map(MacAddress::new)
}
#[must_use]
pub fn raw(&self) -> Arc<LenovoPortSchema> {
self.data.clone()
}
}