use crate::catalog;
use crate::errors::SupplementsError;
use crate::types::{CatalogFile, Product};
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))
}