use reqwest::{Method, Response};
use crate::error_handling::Errors;
use crate::general::{Client, CountryMarketplace};
pub struct CatalogItems;
impl CatalogItems {
pub async fn search_catalog_items(
client: &mut Client,
marketplace_ids: Vec<CountryMarketplace>,
identifiers: Option<Vec<String>>,
identifiers_type: Option<String>,
included_data: Option<Vec<String>>,
locale: Option<String>,
seller_id: Option<String>,
keywords: Option<Vec<String>>,
brand_names: Option<Vec<String>>,
classification_ids: Option<Vec<String>>,
page_size: Option<i32>,
page_token: Option<String>,
keywords_locale: Option<String>,
) -> Result<Response, Errors> {
const URI: &str = "/catalog/2022-04-01/items";
let mut params: Vec<(String, String)> = Vec::new();
params.push(("marketplaceIds".to_string(), marketplace_ids.iter().map(|b|b.details().0.to_string()).collect::<Vec<String>>().join(",")));
if let Some(ids) = identifiers {
params.push(("identifiers".to_string(), ids.join(",")));
}
if let Some(id_type) = identifiers_type {
params.push(("identifiersType".to_string(), id_type));
}
if let Some(data) = included_data {
params.push(("includedData".to_string(), data.join(",")));
}
if let Some(loc) = locale {
params.push(("locale".to_string(), loc));
}
if let Some(sid) = seller_id {
params.push(("sellerId".to_string(), sid));
}
if let Some(kw) = keywords {
params.push(("keywords".to_string(), kw.join(",")));
}
if let Some(brands) = brand_names {
params.push(("brandNames".to_string(), brands.join(",")));
}
if let Some(class_ids) = classification_ids {
params.push(("classificationIds".to_string(), class_ids.join(",")));
}
if let Some(size) = page_size {
params.push(("pageSize".to_string(), size.to_string()));
}
if let Some(token) = page_token {
params.push(("pageToken".to_string(), token));
}
if let Some(kw_locale) = keywords_locale {
params.push(("keywordsLocale".to_string(), kw_locale));
}
client.make_request(URI, Method::GET, Some(params)).await
}
pub async fn get_catalog_item(
client: &mut Client,
asin: String,
marketplace_ids: Vec<CountryMarketplace>,
included_data: Option<Vec<String>>,
locale: Option<String>,
) -> Result<Response, Errors> {
let uri = format!("/catalog/2022-04-01/items/{}", asin);
let mut params: Vec<(String, String)> = Vec::new();
params.push(("marketplaceIds".to_string(), marketplace_ids.iter().map(|b|b.details().0.to_string()).collect::<Vec<String>>().join(",")));
if let Some(data) = included_data {
params.push(("includedData".to_string(), data.join(",")));
}
if let Some(loc) = locale {
params.push(("locale".to_string(), loc));
}
client.make_request(&uri, Method::GET, Some(params)).await
}
}