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 CreateComplaintError {
22 Status400(models::Problem),
23 Status401(models::Problem),
24 Status403(models::Problem),
25 Status404(models::Problem),
26 Status406(models::Problem),
27 Status415(models::Problem),
28 Status500(models::Problem),
29 Status501(models::Problem),
30 Status503(models::Problem),
31 DefaultResponse(models::Problem),
32 UnknownValue(serde_json::Value),
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum GetComplaintError {
39 Status400(models::Problem),
40 Status401(models::Problem),
41 Status403(models::Problem),
42 Status404(models::Problem),
43 Status406(models::Problem),
44 Status415(models::Problem),
45 Status500(models::Problem),
46 Status501(models::Problem),
47 Status503(models::Problem),
48 DefaultResponse(models::Problem),
49 UnknownValue(serde_json::Value),
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum PatchComplaintError {
56 Status400(models::Problem),
57 Status401(models::Problem),
58 Status403(models::Problem),
59 Status404(models::Problem),
60 Status406(models::Problem),
61 Status409(models::Problem),
62 Status415(models::Problem),
63 Status500(models::Problem),
64 Status501(models::Problem),
65 Status503(models::Problem),
66 DefaultResponse(models::Problem),
67 UnknownValue(serde_json::Value),
68}
69
70
71pub async fn create_complaint(configuration: &configuration::Configuration, complaint: models::Complaint, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, idempotency_key: Option<&str>) -> Result<models::ComplaintResponse, Error<CreateComplaintError>> {
73 let p_body_complaint = complaint;
75 let p_header_requestor = requestor;
76 let p_header_accept_language = accept_language;
77 let p_header_traceparent = traceparent;
78 let p_header_tracestate = tracestate;
79 let p_header_idempotency_key = idempotency_key;
80
81 let uri_str = format!("{}/complaints", configuration.base_path);
82 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
83
84 if let Some(ref user_agent) = configuration.user_agent {
85 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
86 }
87 if let Some(param_value) = p_header_requestor {
88 req_builder = req_builder.header("Requestor", param_value.to_string());
89 }
90 if let Some(param_value) = p_header_accept_language {
91 req_builder = req_builder.header("Accept-Language", param_value.to_string());
92 }
93 if let Some(param_value) = p_header_traceparent {
94 req_builder = req_builder.header("traceparent", param_value.to_string());
95 }
96 if let Some(param_value) = p_header_tracestate {
97 req_builder = req_builder.header("tracestate", param_value.to_string());
98 }
99 if let Some(param_value) = p_header_idempotency_key {
100 req_builder = req_builder.header("Idempotency-Key", param_value.to_string());
101 }
102 if let Some(ref token) = configuration.oauth_access_token {
103 req_builder = req_builder.bearer_auth(token.to_owned());
104 };
105 req_builder = req_builder.json(&p_body_complaint);
106
107 let req = req_builder.build()?;
108 let resp = configuration.client.execute(req).await?;
109
110 let status = resp.status();
111 let content_type = resp
112 .headers()
113 .get("content-type")
114 .and_then(|v| v.to_str().ok())
115 .unwrap_or("application/octet-stream");
116 let content_type = super::ContentType::from(content_type);
117
118 if !status.is_client_error() && !status.is_server_error() {
119 let content = resp.text().await?;
120 match content_type {
121 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
122 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ComplaintResponse`"))),
123 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::ComplaintResponse`")))),
124 }
125 } else {
126 let content = resp.text().await?;
127 let entity: Option<CreateComplaintError> = serde_json::from_str(&content).ok();
128 Err(Error::ResponseError(ResponseContent { status, content, entity }))
129 }
130}
131
132pub async fn get_complaint(configuration: &configuration::Configuration, complaint_id: &str, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>) -> Result<models::ComplaintResponse, Error<GetComplaintError>> {
134 let p_path_complaint_id = complaint_id;
136 let p_header_requestor = requestor;
137 let p_header_accept_language = accept_language;
138 let p_header_traceparent = traceparent;
139 let p_header_tracestate = tracestate;
140
141 let uri_str = format!("{}/complaints/{complaintId}", configuration.base_path, complaintId=crate::apis::urlencode(p_path_complaint_id));
142 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
143
144 if let Some(ref user_agent) = configuration.user_agent {
145 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
146 }
147 if let Some(param_value) = p_header_requestor {
148 req_builder = req_builder.header("Requestor", param_value.to_string());
149 }
150 if let Some(param_value) = p_header_accept_language {
151 req_builder = req_builder.header("Accept-Language", param_value.to_string());
152 }
153 if let Some(param_value) = p_header_traceparent {
154 req_builder = req_builder.header("traceparent", param_value.to_string());
155 }
156 if let Some(param_value) = p_header_tracestate {
157 req_builder = req_builder.header("tracestate", param_value.to_string());
158 }
159 if let Some(ref token) = configuration.oauth_access_token {
160 req_builder = req_builder.bearer_auth(token.to_owned());
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::ComplaintResponse`"))),
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::ComplaintResponse`")))),
180 }
181 } else {
182 let content = resp.text().await?;
183 let entity: Option<GetComplaintError> = serde_json::from_str(&content).ok();
184 Err(Error::ResponseError(ResponseContent { status, content, entity }))
185 }
186}
187
188pub async fn patch_complaint(configuration: &configuration::Configuration, complaint_id: &str, complaint_patch_request: models::ComplaintPatchRequest, requestor: Option<&str>, accept_language: Option<&str>, traceparent: Option<&str>, tracestate: Option<&str>, idempotency_key: Option<&str>) -> Result<models::ComplaintResponse, Error<PatchComplaintError>> {
190 let p_path_complaint_id = complaint_id;
192 let p_body_complaint_patch_request = complaint_patch_request;
193 let p_header_requestor = requestor;
194 let p_header_accept_language = accept_language;
195 let p_header_traceparent = traceparent;
196 let p_header_tracestate = tracestate;
197 let p_header_idempotency_key = idempotency_key;
198
199 let uri_str = format!("{}/complaints/{complaintId}", configuration.base_path, complaintId=crate::apis::urlencode(p_path_complaint_id));
200 let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
201
202 if let Some(ref user_agent) = configuration.user_agent {
203 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
204 }
205 if let Some(param_value) = p_header_requestor {
206 req_builder = req_builder.header("Requestor", param_value.to_string());
207 }
208 if let Some(param_value) = p_header_accept_language {
209 req_builder = req_builder.header("Accept-Language", param_value.to_string());
210 }
211 if let Some(param_value) = p_header_traceparent {
212 req_builder = req_builder.header("traceparent", param_value.to_string());
213 }
214 if let Some(param_value) = p_header_tracestate {
215 req_builder = req_builder.header("tracestate", param_value.to_string());
216 }
217 if let Some(param_value) = p_header_idempotency_key {
218 req_builder = req_builder.header("Idempotency-Key", param_value.to_string());
219 }
220 if let Some(ref token) = configuration.oauth_access_token {
221 req_builder = req_builder.bearer_auth(token.to_owned());
222 };
223 req_builder = req_builder.json(&p_body_complaint_patch_request);
224
225 let req = req_builder.build()?;
226 let resp = configuration.client.execute(req).await?;
227
228 let status = resp.status();
229 let content_type = resp
230 .headers()
231 .get("content-type")
232 .and_then(|v| v.to_str().ok())
233 .unwrap_or("application/octet-stream");
234 let content_type = super::ContentType::from(content_type);
235
236 if !status.is_client_error() && !status.is_server_error() {
237 let content = resp.text().await?;
238 match content_type {
239 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
240 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ComplaintResponse`"))),
241 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::ComplaintResponse`")))),
242 }
243 } else {
244 let content = resp.text().await?;
245 let entity: Option<PatchComplaintError> = serde_json::from_str(&content).ok();
246 Err(Error::ResponseError(ResponseContent { status, content, entity }))
247 }
248}
249