1use std::sync::Arc;
12
13use async_trait::async_trait;
14use reqwest;
15use serde::{de::Error as _, Deserialize, Serialize};
16
17use super::{configuration, Error};
18use crate::{
19 apis::{ContentType, ResponseContent},
20 models,
21};
22
23#[async_trait]
24pub trait LogsApi: Send + Sync {
25 async fn logging_controller_logs_delete_query<
27 'r_type,
28 'assistant_id,
29 'phone_number_id,
30 'customer_id,
31 'squad_id,
32 'call_id,
33 >(
34 &self,
35 r#type: Option<&'r_type str>,
36 assistant_id: Option<&'assistant_id str>,
37 phone_number_id: Option<&'phone_number_id str>,
38 customer_id: Option<&'customer_id str>,
39 squad_id: Option<&'squad_id str>,
40 call_id: Option<&'call_id str>,
41 ) -> Result<(), Error<LoggingControllerLogsDeleteQueryError>>;
42
43 async fn logging_controller_logs_query<
45 'r_type,
46 'webhook_type,
47 'assistant_id,
48 'phone_number_id,
49 'customer_id,
50 'squad_id,
51 'call_id,
52 'page,
53 'sort_order,
54 'limit,
55 'created_at_gt,
56 'created_at_lt,
57 'created_at_ge,
58 'created_at_le,
59 'updated_at_gt,
60 'updated_at_lt,
61 'updated_at_ge,
62 'updated_at_le,
63 >(
64 &self,
65 r#type: Option<&'r_type str>,
66 webhook_type: Option<&'webhook_type str>,
67 assistant_id: Option<&'assistant_id str>,
68 phone_number_id: Option<&'phone_number_id str>,
69 customer_id: Option<&'customer_id str>,
70 squad_id: Option<&'squad_id str>,
71 call_id: Option<&'call_id str>,
72 page: Option<f64>,
73 sort_order: Option<&'sort_order str>,
74 limit: Option<f64>,
75 created_at_gt: Option<String>,
76 created_at_lt: Option<String>,
77 created_at_ge: Option<String>,
78 created_at_le: Option<String>,
79 updated_at_gt: Option<String>,
80 updated_at_lt: Option<String>,
81 updated_at_ge: Option<String>,
82 updated_at_le: Option<String>,
83 ) -> Result<models::LogsPaginatedResponse, Error<LoggingControllerLogsQueryError>>;
84}
85
86pub struct LogsApiClient {
87 configuration: Arc<configuration::Configuration>,
88}
89
90impl LogsApiClient {
91 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
92 Self { configuration }
93 }
94}
95
96#[async_trait]
97impl LogsApi for LogsApiClient {
98 async fn logging_controller_logs_delete_query<
99 'r_type,
100 'assistant_id,
101 'phone_number_id,
102 'customer_id,
103 'squad_id,
104 'call_id,
105 >(
106 &self,
107 r#type: Option<&'r_type str>,
108 assistant_id: Option<&'assistant_id str>,
109 phone_number_id: Option<&'phone_number_id str>,
110 customer_id: Option<&'customer_id str>,
111 squad_id: Option<&'squad_id str>,
112 call_id: Option<&'call_id str>,
113 ) -> Result<(), Error<LoggingControllerLogsDeleteQueryError>> {
114 let local_var_configuration = &self.configuration;
115
116 let local_var_client = &local_var_configuration.client;
117
118 let local_var_uri_str = format!("{}/logs", local_var_configuration.base_path);
119 let mut local_var_req_builder =
120 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
121
122 if let Some(ref local_var_str) = r#type {
123 local_var_req_builder =
124 local_var_req_builder.query(&[("type", &local_var_str.to_string())]);
125 }
126 if let Some(ref local_var_str) = assistant_id {
127 local_var_req_builder =
128 local_var_req_builder.query(&[("assistantId", &local_var_str.to_string())]);
129 }
130 if let Some(ref local_var_str) = phone_number_id {
131 local_var_req_builder =
132 local_var_req_builder.query(&[("phoneNumberId", &local_var_str.to_string())]);
133 }
134 if let Some(ref local_var_str) = customer_id {
135 local_var_req_builder =
136 local_var_req_builder.query(&[("customerId", &local_var_str.to_string())]);
137 }
138 if let Some(ref local_var_str) = squad_id {
139 local_var_req_builder =
140 local_var_req_builder.query(&[("squadId", &local_var_str.to_string())]);
141 }
142 if let Some(ref local_var_str) = call_id {
143 local_var_req_builder =
144 local_var_req_builder.query(&[("callId", &local_var_str.to_string())]);
145 }
146 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
147 local_var_req_builder = local_var_req_builder
148 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
149 }
150 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
151 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
152 };
153
154 let local_var_req = local_var_req_builder.build()?;
155 let local_var_resp = local_var_client.execute(local_var_req).await?;
156
157 let local_var_status = local_var_resp.status();
158 let local_var_content = local_var_resp.text().await?;
159
160 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
161 Ok(())
162 } else {
163 let local_var_entity: Option<LoggingControllerLogsDeleteQueryError> =
164 serde_json::from_str(&local_var_content).ok();
165 let local_var_error = ResponseContent {
166 status: local_var_status,
167 content: local_var_content,
168 entity: local_var_entity,
169 };
170 Err(Error::ResponseError(local_var_error))
171 }
172 }
173
174 async fn logging_controller_logs_query<
175 'r_type,
176 'webhook_type,
177 'assistant_id,
178 'phone_number_id,
179 'customer_id,
180 'squad_id,
181 'call_id,
182 'page,
183 'sort_order,
184 'limit,
185 'created_at_gt,
186 'created_at_lt,
187 'created_at_ge,
188 'created_at_le,
189 'updated_at_gt,
190 'updated_at_lt,
191 'updated_at_ge,
192 'updated_at_le,
193 >(
194 &self,
195 r#type: Option<&'r_type str>,
196 webhook_type: Option<&'webhook_type str>,
197 assistant_id: Option<&'assistant_id str>,
198 phone_number_id: Option<&'phone_number_id str>,
199 customer_id: Option<&'customer_id str>,
200 squad_id: Option<&'squad_id str>,
201 call_id: Option<&'call_id str>,
202 page: Option<f64>,
203 sort_order: Option<&'sort_order str>,
204 limit: Option<f64>,
205 created_at_gt: Option<String>,
206 created_at_lt: Option<String>,
207 created_at_ge: Option<String>,
208 created_at_le: Option<String>,
209 updated_at_gt: Option<String>,
210 updated_at_lt: Option<String>,
211 updated_at_ge: Option<String>,
212 updated_at_le: Option<String>,
213 ) -> Result<models::LogsPaginatedResponse, Error<LoggingControllerLogsQueryError>> {
214 let local_var_configuration = &self.configuration;
215
216 let local_var_client = &local_var_configuration.client;
217
218 let local_var_uri_str = format!("{}/logs", local_var_configuration.base_path);
219 let mut local_var_req_builder =
220 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
221
222 if let Some(ref local_var_str) = r#type {
223 local_var_req_builder =
224 local_var_req_builder.query(&[("type", &local_var_str.to_string())]);
225 }
226 if let Some(ref local_var_str) = webhook_type {
227 local_var_req_builder =
228 local_var_req_builder.query(&[("webhookType", &local_var_str.to_string())]);
229 }
230 if let Some(ref local_var_str) = assistant_id {
231 local_var_req_builder =
232 local_var_req_builder.query(&[("assistantId", &local_var_str.to_string())]);
233 }
234 if let Some(ref local_var_str) = phone_number_id {
235 local_var_req_builder =
236 local_var_req_builder.query(&[("phoneNumberId", &local_var_str.to_string())]);
237 }
238 if let Some(ref local_var_str) = customer_id {
239 local_var_req_builder =
240 local_var_req_builder.query(&[("customerId", &local_var_str.to_string())]);
241 }
242 if let Some(ref local_var_str) = squad_id {
243 local_var_req_builder =
244 local_var_req_builder.query(&[("squadId", &local_var_str.to_string())]);
245 }
246 if let Some(ref local_var_str) = call_id {
247 local_var_req_builder =
248 local_var_req_builder.query(&[("callId", &local_var_str.to_string())]);
249 }
250 if let Some(ref local_var_str) = page {
251 local_var_req_builder =
252 local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
253 }
254 if let Some(ref local_var_str) = sort_order {
255 local_var_req_builder =
256 local_var_req_builder.query(&[("sortOrder", &local_var_str.to_string())]);
257 }
258 if let Some(ref local_var_str) = limit {
259 local_var_req_builder =
260 local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
261 }
262 if let Some(ref local_var_str) = created_at_gt {
263 local_var_req_builder =
264 local_var_req_builder.query(&[("createdAtGt", &local_var_str.to_string())]);
265 }
266 if let Some(ref local_var_str) = created_at_lt {
267 local_var_req_builder =
268 local_var_req_builder.query(&[("createdAtLt", &local_var_str.to_string())]);
269 }
270 if let Some(ref local_var_str) = created_at_ge {
271 local_var_req_builder =
272 local_var_req_builder.query(&[("createdAtGe", &local_var_str.to_string())]);
273 }
274 if let Some(ref local_var_str) = created_at_le {
275 local_var_req_builder =
276 local_var_req_builder.query(&[("createdAtLe", &local_var_str.to_string())]);
277 }
278 if let Some(ref local_var_str) = updated_at_gt {
279 local_var_req_builder =
280 local_var_req_builder.query(&[("updatedAtGt", &local_var_str.to_string())]);
281 }
282 if let Some(ref local_var_str) = updated_at_lt {
283 local_var_req_builder =
284 local_var_req_builder.query(&[("updatedAtLt", &local_var_str.to_string())]);
285 }
286 if let Some(ref local_var_str) = updated_at_ge {
287 local_var_req_builder =
288 local_var_req_builder.query(&[("updatedAtGe", &local_var_str.to_string())]);
289 }
290 if let Some(ref local_var_str) = updated_at_le {
291 local_var_req_builder =
292 local_var_req_builder.query(&[("updatedAtLe", &local_var_str.to_string())]);
293 }
294 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
295 local_var_req_builder = local_var_req_builder
296 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
297 }
298 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
299 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
300 };
301
302 let local_var_req = local_var_req_builder.build()?;
303 let local_var_resp = local_var_client.execute(local_var_req).await?;
304
305 let local_var_status = local_var_resp.status();
306 let local_var_content_type = local_var_resp
307 .headers()
308 .get("content-type")
309 .and_then(|v| v.to_str().ok())
310 .unwrap_or("application/octet-stream");
311 let local_var_content_type = super::ContentType::from(local_var_content_type);
312 let local_var_content = local_var_resp.text().await?;
313
314 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
315 match local_var_content_type {
316 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
317 ContentType::Text => {
318 return Err(Error::from(serde_json::Error::custom(
319 "Received `text/plain` content type response that cannot be converted to \
320 `models::LogsPaginatedResponse`",
321 )))
322 }
323 ContentType::Unsupported(local_var_unknown_type) => {
324 return Err(Error::from(serde_json::Error::custom(format!(
325 "Received `{local_var_unknown_type}` content type response that cannot be \
326 converted to `models::LogsPaginatedResponse`"
327 ))))
328 }
329 }
330 } else {
331 let local_var_entity: Option<LoggingControllerLogsQueryError> =
332 serde_json::from_str(&local_var_content).ok();
333 let local_var_error = ResponseContent {
334 status: local_var_status,
335 content: local_var_content,
336 entity: local_var_entity,
337 };
338 Err(Error::ResponseError(local_var_error))
339 }
340 }
341}
342
343#[derive(Debug, Clone, Serialize, Deserialize)]
345#[serde(untagged)]
346pub enum LoggingControllerLogsDeleteQueryError {
347 UnknownValue(serde_json::Value),
348}
349
350#[derive(Debug, Clone, Serialize, Deserialize)]
352#[serde(untagged)]
353pub enum LoggingControllerLogsQueryError {
354 UnknownValue(serde_json::Value),
355}