use crate::core::Bmc;
use crate::core::EdmPrimitiveType;
use crate::oem::dell::schema::dell_attributes::DellAttributes as DellAttributesSchema;
use std::marker::PhantomData;
use std::sync::Arc;
#[cfg(feature = "managers")]
use crate::core::EntityTypeRef as _;
#[cfg(feature = "managers")]
use crate::core::NavProperty;
#[cfg(feature = "managers")]
use crate::core::ODataId;
#[cfg(feature = "managers")]
use crate::schema::manager::Manager as ManagerSchema;
#[cfg(feature = "managers")]
use crate::Error;
#[cfg(feature = "managers")]
use crate::NvBmc;
pub struct DellAttributes<B: Bmc> {
data: Arc<DellAttributesSchema>,
_marker: PhantomData<B>,
}
impl<B: Bmc> DellAttributes<B> {
#[cfg(feature = "managers")]
pub(crate) async fn manager_attributes(
bmc: &NvBmc<B>,
manager: &ManagerSchema,
) -> Result<Option<Self>, Error<B>> {
if manager
.base
.base
.oem
.as_ref()
.is_some_and(|oem| oem.additional_properties.get("Dell").is_some())
{
let odata_id = ODataId::from(format!(
"{}/Oem/Dell/DellAttributes/{}",
manager.odata_id(),
manager.base.id
));
bmc.expand_property(&NavProperty::new_reference(odata_id))
.await
.map(|data| Self {
data,
_marker: PhantomData,
})
.map(Some)
} else {
Ok(None)
}
}
#[must_use]
pub fn attribute<'a>(&'a self, name: &str) -> Option<DellAttributeRef<'a>> {
self.data
.attributes
.as_ref()
.and_then(|attributes| attributes.dynamic_properties.get(name))
.map(|v| DellAttributeRef::new(v.as_ref()))
}
}
pub struct DellAttributeRef<'a> {
value: Option<&'a EdmPrimitiveType>,
}
impl<'a> DellAttributeRef<'a> {
const fn new(value: Option<&'a EdmPrimitiveType>) -> Self {
Self { value }
}
#[must_use]
pub const fn is_null(&self) -> bool {
self.value.is_none()
}
#[must_use]
pub const fn str_value(&self) -> Option<&str> {
match self.value {
Some(EdmPrimitiveType::String(v)) => Some(v.as_str()),
_ => None,
}
}
#[must_use]
pub const fn bool_value(&self) -> Option<bool> {
match self.value {
Some(EdmPrimitiveType::Bool(v)) => Some(*v),
_ => None,
}
}
#[must_use]
pub const fn integer_value(&self) -> Option<i64> {
match self.value {
Some(EdmPrimitiveType::Integer(v)) => Some(*v),
_ => None,
}
}
#[must_use]
pub const fn decimal_value(&self) -> Option<f64> {
match self.value {
Some(EdmPrimitiveType::Decimal(v)) => Some(*v),
_ => None,
}
}
}