agent-supplements-rec 0.1.0

Curated supplement recommendation engine for longevity biomarker optimization
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::catalog;
use crate::errors::SupplementsError;
use crate::types::{CatalogFile, Product};

/// Get a product by ID with its brand name.
pub fn get_product_detail<'a>(
    catalog_file: &'a CatalogFile,
    product_id: &str,
) -> Result<(&'a Product, String), SupplementsError> {
    let product = catalog::find_product(catalog_file, product_id)
        .ok_or_else(|| SupplementsError::ProductNotFound(product_id.to_string()))?;

    let brand_name = catalog::find_brand(catalog_file, &product.brand_id)
        .map(|b| b.name.clone())
        .unwrap_or_else(|| product.brand_id.clone());

    Ok((product, brand_name))
}