1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AddInventoryError {
22 Status400(models::fba_inventory::AddInventoryResponse),
23 Status403(models::fba_inventory::AddInventoryResponse),
24 Status404(models::fba_inventory::AddInventoryResponse),
25 Status429(models::fba_inventory::AddInventoryResponse),
26 Status500(models::fba_inventory::AddInventoryResponse),
27 Status503(models::fba_inventory::AddInventoryResponse),
28 UnknownValue(serde_json::Value),
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum CreateInventoryItemError {
35 Status400(models::fba_inventory::CreateInventoryItemResponse),
36 Status403(models::fba_inventory::CreateInventoryItemResponse),
37 Status404(models::fba_inventory::CreateInventoryItemResponse),
38 Status429(models::fba_inventory::CreateInventoryItemResponse),
39 Status500(models::fba_inventory::CreateInventoryItemResponse),
40 Status503(models::fba_inventory::CreateInventoryItemResponse),
41 UnknownValue(serde_json::Value),
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(untagged)]
47pub enum DeleteInventoryItemError {
48 Status400(models::fba_inventory::DeleteInventoryItemResponse),
49 Status403(models::fba_inventory::DeleteInventoryItemResponse),
50 Status404(models::fba_inventory::DeleteInventoryItemResponse),
51 Status429(models::fba_inventory::DeleteInventoryItemResponse),
52 Status500(models::fba_inventory::DeleteInventoryItemResponse),
53 Status503(models::fba_inventory::DeleteInventoryItemResponse),
54 UnknownValue(serde_json::Value),
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(untagged)]
60pub enum GetInventorySummariesError {
61 Status400(models::fba_inventory::GetInventorySummariesResponse),
62 Status403(models::fba_inventory::GetInventorySummariesResponse),
63 Status404(models::fba_inventory::GetInventorySummariesResponse),
64 Status429(models::fba_inventory::GetInventorySummariesResponse),
65 Status500(models::fba_inventory::GetInventorySummariesResponse),
66 Status503(models::fba_inventory::GetInventorySummariesResponse),
67 UnknownValue(serde_json::Value),
68}
69
70
71pub async fn add_inventory(configuration: &configuration::Configuration, x_amzn_idempotency_token: &str, add_inventory_request_body: models::fba_inventory::AddInventoryRequest) -> Result<models::fba_inventory::AddInventoryResponse, Error<AddInventoryError>> {
73 let p_x_amzn_idempotency_token = x_amzn_idempotency_token;
75 let p_add_inventory_request_body = add_inventory_request_body;
76
77 let uri_str = format!("{}/fba/inventory/v1/items/inventory", configuration.base_path);
78 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
79
80 if let Some(ref user_agent) = configuration.user_agent {
81 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
82 }
83 req_builder = req_builder.header("x-amzn-idempotency-token", p_x_amzn_idempotency_token.to_string());
84 req_builder = req_builder.json(&p_add_inventory_request_body);
85
86 let req = req_builder.build()?;
87 let resp = configuration.client.execute(req).await?;
88
89 let status = resp.status();
90 let content_type = resp
91 .headers()
92 .get("content-type")
93 .and_then(|v| v.to_str().ok())
94 .unwrap_or("application/octet-stream");
95 let content_type = super::ContentType::from(content_type);
96
97 if !status.is_client_error() && !status.is_server_error() {
98 let content = resp.text().await?;
99 match content_type {
100 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
101 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::fba_inventory::AddInventoryResponse`"))),
102 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::fba_inventory::AddInventoryResponse`")))),
103 }
104 } else {
105 let content = resp.text().await?;
106 let entity: Option<AddInventoryError> = serde_json::from_str(&content).ok();
107 Err(Error::ResponseError(ResponseContent { status, content, entity }))
108 }
109}
110
111pub async fn create_inventory_item(configuration: &configuration::Configuration, create_inventory_item_request_body: models::fba_inventory::CreateInventoryItemRequest) -> Result<models::fba_inventory::CreateInventoryItemResponse, Error<CreateInventoryItemError>> {
113 let p_create_inventory_item_request_body = create_inventory_item_request_body;
115
116 let uri_str = format!("{}/fba/inventory/v1/items", configuration.base_path);
117 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
118
119 if let Some(ref user_agent) = configuration.user_agent {
120 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
121 }
122 req_builder = req_builder.json(&p_create_inventory_item_request_body);
123
124 let req = req_builder.build()?;
125 let resp = configuration.client.execute(req).await?;
126
127 let status = resp.status();
128 let content_type = resp
129 .headers()
130 .get("content-type")
131 .and_then(|v| v.to_str().ok())
132 .unwrap_or("application/octet-stream");
133 let content_type = super::ContentType::from(content_type);
134
135 if !status.is_client_error() && !status.is_server_error() {
136 let content = resp.text().await?;
137 match content_type {
138 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
139 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::fba_inventory::CreateInventoryItemResponse`"))),
140 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::fba_inventory::CreateInventoryItemResponse`")))),
141 }
142 } else {
143 let content = resp.text().await?;
144 let entity: Option<CreateInventoryItemError> = serde_json::from_str(&content).ok();
145 Err(Error::ResponseError(ResponseContent { status, content, entity }))
146 }
147}
148
149pub async fn delete_inventory_item(configuration: &configuration::Configuration, seller_sku: &str, marketplace_id: &str) -> Result<models::fba_inventory::DeleteInventoryItemResponse, Error<DeleteInventoryItemError>> {
151 let p_seller_sku = seller_sku;
153 let p_marketplace_id = marketplace_id;
154
155 let uri_str = format!("{}/fba/inventory/v1/items/{sellerSku}", configuration.base_path, sellerSku=crate::apis::urlencode(p_seller_sku));
156 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
157
158 req_builder = req_builder.query(&[("marketplaceId", &p_marketplace_id.to_string())]);
159 if let Some(ref user_agent) = configuration.user_agent {
160 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
161 }
162
163 let req = req_builder.build()?;
164 let resp = configuration.client.execute(req).await?;
165
166 let status = resp.status();
167 let content_type = resp
168 .headers()
169 .get("content-type")
170 .and_then(|v| v.to_str().ok())
171 .unwrap_or("application/octet-stream");
172 let content_type = super::ContentType::from(content_type);
173
174 if !status.is_client_error() && !status.is_server_error() {
175 let content = resp.text().await?;
176 match content_type {
177 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
178 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::fba_inventory::DeleteInventoryItemResponse`"))),
179 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::fba_inventory::DeleteInventoryItemResponse`")))),
180 }
181 } else {
182 let content = resp.text().await?;
183 let entity: Option<DeleteInventoryItemError> = serde_json::from_str(&content).ok();
184 Err(Error::ResponseError(ResponseContent { status, content, entity }))
185 }
186}
187
188pub async fn get_inventory_summaries(configuration: &configuration::Configuration, granularity_type: &str, granularity_id: &str, marketplace_ids: Vec<String>, details: Option<bool>, start_date_time: Option<String>, seller_skus: Option<Vec<String>>, seller_sku: Option<&str>, next_token: Option<&str>) -> Result<models::fba_inventory::GetInventorySummariesResponse, Error<GetInventorySummariesError>> {
190 let p_granularity_type = granularity_type;
192 let p_granularity_id = granularity_id;
193 let p_marketplace_ids = marketplace_ids;
194 let p_details = details;
195 let p_start_date_time = start_date_time;
196 let p_seller_skus = seller_skus;
197 let p_seller_sku = seller_sku;
198 let p_next_token = next_token;
199
200 let uri_str = format!("{}/fba/inventory/v1/summaries", configuration.base_path);
201 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
202
203 if let Some(ref param_value) = p_details {
204 req_builder = req_builder.query(&[("details", ¶m_value.to_string())]);
205 }
206 req_builder = req_builder.query(&[("granularityType", &p_granularity_type.to_string())]);
207 req_builder = req_builder.query(&[("granularityId", &p_granularity_id.to_string())]);
208 if let Some(ref param_value) = p_start_date_time {
209 req_builder = req_builder.query(&[("startDateTime", ¶m_value.to_string())]);
210 }
211 if let Some(ref param_value) = p_seller_skus {
212 req_builder = match "csv" {
213 "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("sellerSkus".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
214 _ => req_builder.query(&[("sellerSkus", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
215 };
216 }
217 if let Some(ref param_value) = p_seller_sku {
218 req_builder = req_builder.query(&[("sellerSku", ¶m_value.to_string())]);
219 }
220 if let Some(ref param_value) = p_next_token {
221 req_builder = req_builder.query(&[("nextToken", ¶m_value.to_string())]);
222 }
223 req_builder = match "csv" {
224 "multi" => req_builder.query(&p_marketplace_ids.into_iter().map(|p| ("marketplaceIds".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
225 _ => req_builder.query(&[("marketplaceIds", &p_marketplace_ids.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
226 };
227 if let Some(ref user_agent) = configuration.user_agent {
228 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
229 }
230
231 let req = req_builder.build()?;
232 let resp = configuration.client.execute(req).await?;
233
234 let status = resp.status();
235 let content_type = resp
236 .headers()
237 .get("content-type")
238 .and_then(|v| v.to_str().ok())
239 .unwrap_or("application/octet-stream");
240 let content_type = super::ContentType::from(content_type);
241
242 if !status.is_client_error() && !status.is_server_error() {
243 let content = resp.text().await?;
244 match content_type {
245 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
246 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::fba_inventory::GetInventorySummariesResponse`"))),
247 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::fba_inventory::GetInventorySummariesResponse`")))),
248 }
249 } else {
250 let content = resp.text().await?;
251 let entity: Option<GetInventorySummariesError> = serde_json::from_str(&content).ok();
252 Err(Error::ResponseError(ResponseContent { status, content, entity }))
253 }
254}
255