agent-device-rec 0.1.0

Health device recommendation engine for longevity monitoring
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::catalog;
use crate::errors::DeviceError;
use crate::types::DeviceCatalogFile;

/// Look up a single device by ID and return it with its brand name.
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))
}