use crate::catalog;
use crate::errors::DeviceError;
use crate::types::DeviceCatalogFile;
pub fn show_device<'a>(
catalog: &'a DeviceCatalogFile,
device_id: &str,
) -> Result<(&'a crate::types::Device, String), DeviceError> {
let device = catalog::find_device(catalog, device_id)
.ok_or_else(|| DeviceError::DeviceNotFound(device_id.to_string()))?;
let brand_name = catalog::find_brand(catalog, &device.brand_id)
.map(|b| b.name.clone())
.unwrap_or_else(|| device.brand_id.clone());
Ok((device, brand_name))
}