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 DeleteRecommendationError {
22 Status401(models::ApiError),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum GetRecommendationError {
30 Status401(models::ApiError),
31 Status404(models::ApiError),
32 UnknownValue(serde_json::Value),
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum ListRecommendationsError {
39 Status401(models::ApiError),
40 UnknownValue(serde_json::Value),
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
45#[serde(untagged)]
46pub enum ProposeRecommendationError {
47 Status401(models::ApiError),
48 UnknownValue(serde_json::Value),
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum UpdateRecommendationStatusError {
55 Status401(models::ApiError),
56 Status404(models::ApiError),
57 UnknownValue(serde_json::Value),
58}
59
60
61pub async fn delete_recommendation(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteRecommendationError>> {
62 let p_path_id = id;
64
65 let uri_str = format!("{}/v1/recommendations/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
66 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
67
68 if let Some(ref user_agent) = configuration.user_agent {
69 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
70 }
71 if let Some(ref token) = configuration.bearer_access_token {
72 req_builder = req_builder.bearer_auth(token.to_owned());
73 };
74
75 let req = req_builder.build()?;
76 let resp = configuration.client.execute(req).await?;
77
78 let status = resp.status();
79
80 if !status.is_client_error() && !status.is_server_error() {
81 Ok(())
82 } else {
83 let content = resp.text().await?;
84 let entity: Option<DeleteRecommendationError> = serde_json::from_str(&content).ok();
85 Err(Error::ResponseError(ResponseContent { status, content, entity }))
86 }
87}
88
89pub async fn get_recommendation(configuration: &configuration::Configuration, id: &str) -> Result<models::Recommendation, Error<GetRecommendationError>> {
90 let p_path_id = id;
92
93 let uri_str = format!("{}/v1/recommendations/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
94 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
95
96 if let Some(ref user_agent) = configuration.user_agent {
97 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
98 }
99 if let Some(ref token) = configuration.bearer_access_token {
100 req_builder = req_builder.bearer_auth(token.to_owned());
101 };
102
103 let req = req_builder.build()?;
104 let resp = configuration.client.execute(req).await?;
105
106 let status = resp.status();
107 let content_type = resp
108 .headers()
109 .get("content-type")
110 .and_then(|v| v.to_str().ok())
111 .unwrap_or("application/octet-stream");
112 let content_type = super::ContentType::from(content_type);
113
114 if !status.is_client_error() && !status.is_server_error() {
115 let content = resp.text().await?;
116 match content_type {
117 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
118 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Recommendation`"))),
119 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::Recommendation`")))),
120 }
121 } else {
122 let content = resp.text().await?;
123 let entity: Option<GetRecommendationError> = serde_json::from_str(&content).ok();
124 Err(Error::ResponseError(ResponseContent { status, content, entity }))
125 }
126}
127
128pub async fn list_recommendations(configuration: &configuration::Configuration, workspace_id: Option<&str>, status: Option<&str>, limit: Option<i32>) -> Result<models::RecommendationListResponse, Error<ListRecommendationsError>> {
129 let p_query_workspace_id = workspace_id;
131 let p_query_status = status;
132 let p_query_limit = limit;
133
134 let uri_str = format!("{}/v1/recommendations", configuration.base_path);
135 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
136
137 if let Some(ref param_value) = p_query_workspace_id {
138 req_builder = req_builder.query(&[("workspaceId", ¶m_value.to_string())]);
139 }
140 if let Some(ref param_value) = p_query_status {
141 req_builder = req_builder.query(&[("status", ¶m_value.to_string())]);
142 }
143 if let Some(ref param_value) = p_query_limit {
144 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
145 }
146 if let Some(ref user_agent) = configuration.user_agent {
147 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
148 }
149 if let Some(ref token) = configuration.bearer_access_token {
150 req_builder = req_builder.bearer_auth(token.to_owned());
151 };
152
153 let req = req_builder.build()?;
154 let resp = configuration.client.execute(req).await?;
155
156 let status = resp.status();
157 let content_type = resp
158 .headers()
159 .get("content-type")
160 .and_then(|v| v.to_str().ok())
161 .unwrap_or("application/octet-stream");
162 let content_type = super::ContentType::from(content_type);
163
164 if !status.is_client_error() && !status.is_server_error() {
165 let content = resp.text().await?;
166 match content_type {
167 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
168 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RecommendationListResponse`"))),
169 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::RecommendationListResponse`")))),
170 }
171 } else {
172 let content = resp.text().await?;
173 let entity: Option<ListRecommendationsError> = serde_json::from_str(&content).ok();
174 Err(Error::ResponseError(ResponseContent { status, content, entity }))
175 }
176}
177
178pub async fn propose_recommendation(configuration: &configuration::Configuration, propose_recommendation_request: models::ProposeRecommendationRequest) -> Result<models::Recommendation, Error<ProposeRecommendationError>> {
179 let p_body_propose_recommendation_request = propose_recommendation_request;
181
182 let uri_str = format!("{}/v1/recommendations", configuration.base_path);
183 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
184
185 if let Some(ref user_agent) = configuration.user_agent {
186 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
187 }
188 if let Some(ref token) = configuration.bearer_access_token {
189 req_builder = req_builder.bearer_auth(token.to_owned());
190 };
191 req_builder = req_builder.json(&p_body_propose_recommendation_request);
192
193 let req = req_builder.build()?;
194 let resp = configuration.client.execute(req).await?;
195
196 let status = resp.status();
197 let content_type = resp
198 .headers()
199 .get("content-type")
200 .and_then(|v| v.to_str().ok())
201 .unwrap_or("application/octet-stream");
202 let content_type = super::ContentType::from(content_type);
203
204 if !status.is_client_error() && !status.is_server_error() {
205 let content = resp.text().await?;
206 match content_type {
207 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
208 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Recommendation`"))),
209 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::Recommendation`")))),
210 }
211 } else {
212 let content = resp.text().await?;
213 let entity: Option<ProposeRecommendationError> = serde_json::from_str(&content).ok();
214 Err(Error::ResponseError(ResponseContent { status, content, entity }))
215 }
216}
217
218pub async fn update_recommendation_status(configuration: &configuration::Configuration, id: &str, update_recommendation_status_request: models::UpdateRecommendationStatusRequest) -> Result<models::Recommendation, Error<UpdateRecommendationStatusError>> {
219 let p_path_id = id;
221 let p_body_update_recommendation_status_request = update_recommendation_status_request;
222
223 let uri_str = format!("{}/v1/recommendations/{id}/status", configuration.base_path, id=crate::apis::urlencode(p_path_id));
224 let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
225
226 if let Some(ref user_agent) = configuration.user_agent {
227 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
228 }
229 if let Some(ref token) = configuration.bearer_access_token {
230 req_builder = req_builder.bearer_auth(token.to_owned());
231 };
232 req_builder = req_builder.json(&p_body_update_recommendation_status_request);
233
234 let req = req_builder.build()?;
235 let resp = configuration.client.execute(req).await?;
236
237 let status = resp.status();
238 let content_type = resp
239 .headers()
240 .get("content-type")
241 .and_then(|v| v.to_str().ok())
242 .unwrap_or("application/octet-stream");
243 let content_type = super::ContentType::from(content_type);
244
245 if !status.is_client_error() && !status.is_server_error() {
246 let content = resp.text().await?;
247 match content_type {
248 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
249 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Recommendation`"))),
250 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::Recommendation`")))),
251 }
252 } else {
253 let content = resp.text().await?;
254 let entity: Option<UpdateRecommendationStatusError> = serde_json::from_str(&content).ok();
255 Err(Error::ResponseError(ResponseContent { status, content, entity }))
256 }
257}
258