1use std::sync::Arc;
12
13use async_trait::async_trait;
14#[cfg(feature = "mockall")]
15use mockall::automock;
16use reqwest;
17use serde::{Deserialize, Serialize, de::Error as _};
18
19use super::{Error, configuration};
20use crate::{
21 apis::{AuthRequired, ContentType, ResponseContent},
22 models,
23};
24
25#[cfg_attr(feature = "mockall", automock)]
26#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
28pub trait GroupsApi: Send + Sync {
29 async fn bulk_delete<'a>(
31 &self,
32 org_id: &'a str,
33 group_bulk_request_model: Option<models::GroupBulkRequestModel>,
34 ) -> Result<(), Error<BulkDeleteError>>;
35
36 async fn delete<'a>(&self, org_id: &'a str, id: &'a str) -> Result<(), Error<DeleteError>>;
38
39 async fn delete_user<'a>(
41 &self,
42 org_id: &'a str,
43 id: &'a str,
44 org_user_id: &'a str,
45 ) -> Result<(), Error<DeleteUserError>>;
46
47 async fn get<'a>(
49 &self,
50 org_id: &'a str,
51 id: &'a str,
52 ) -> Result<models::GroupResponseModel, Error<GetError>>;
53
54 async fn get_details<'a>(
56 &self,
57 org_id: &'a str,
58 id: &'a str,
59 ) -> Result<models::GroupDetailsResponseModel, Error<GetDetailsError>>;
60
61 async fn get_organization_group_details<'a>(
63 &self,
64 org_id: uuid::Uuid,
65 ) -> Result<
66 models::GroupDetailsResponseModelListResponseModel,
67 Error<GetOrganizationGroupDetailsError>,
68 >;
69
70 async fn get_organization_groups<'a>(
72 &self,
73 org_id: uuid::Uuid,
74 ) -> Result<models::GroupResponseModelListResponseModel, Error<GetOrganizationGroupsError>>;
75
76 async fn get_users<'a>(
78 &self,
79 org_id: &'a str,
80 id: &'a str,
81 ) -> Result<Vec<uuid::Uuid>, Error<GetUsersError>>;
82
83 async fn post<'a>(
85 &self,
86 org_id: uuid::Uuid,
87 group_request_model: Option<models::GroupRequestModel>,
88 ) -> Result<models::GroupResponseModel, Error<PostError>>;
89
90 async fn put<'a>(
92 &self,
93 org_id: uuid::Uuid,
94 id: uuid::Uuid,
95 group_request_model: Option<models::GroupRequestModel>,
96 ) -> Result<models::GroupResponseModel, Error<PutError>>;
97}
98
99pub struct GroupsApiClient {
100 configuration: Arc<configuration::Configuration>,
101}
102
103impl GroupsApiClient {
104 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
105 Self { configuration }
106 }
107}
108
109#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
110#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
111impl GroupsApi for GroupsApiClient {
112 async fn bulk_delete<'a>(
113 &self,
114 org_id: &'a str,
115 group_bulk_request_model: Option<models::GroupBulkRequestModel>,
116 ) -> Result<(), Error<BulkDeleteError>> {
117 let local_var_configuration = &self.configuration;
118
119 let local_var_client = &local_var_configuration.client;
120
121 let local_var_uri_str = format!(
122 "{}/organizations/{orgId}/groups",
123 local_var_configuration.base_path,
124 orgId = crate::apis::urlencode(org_id)
125 );
126 let mut local_var_req_builder =
127 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
128
129 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
130 local_var_req_builder = local_var_req_builder.json(&group_bulk_request_model);
131
132 let local_var_resp = local_var_req_builder.send().await?;
133
134 let local_var_status = local_var_resp.status();
135 let local_var_content = local_var_resp.text().await?;
136
137 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
138 Ok(())
139 } else {
140 let local_var_entity: Option<BulkDeleteError> =
141 serde_json::from_str(&local_var_content).ok();
142 let local_var_error = ResponseContent {
143 status: local_var_status,
144 content: local_var_content,
145 entity: local_var_entity,
146 };
147 Err(Error::ResponseError(local_var_error))
148 }
149 }
150
151 async fn delete<'a>(&self, org_id: &'a str, id: &'a str) -> Result<(), Error<DeleteError>> {
152 let local_var_configuration = &self.configuration;
153
154 let local_var_client = &local_var_configuration.client;
155
156 let local_var_uri_str = format!(
157 "{}/organizations/{orgId}/groups/{id}",
158 local_var_configuration.base_path,
159 orgId = crate::apis::urlencode(org_id),
160 id = crate::apis::urlencode(id)
161 );
162 let mut local_var_req_builder =
163 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
164
165 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
166
167 let local_var_resp = local_var_req_builder.send().await?;
168
169 let local_var_status = local_var_resp.status();
170 let local_var_content = local_var_resp.text().await?;
171
172 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
173 Ok(())
174 } else {
175 let local_var_entity: Option<DeleteError> =
176 serde_json::from_str(&local_var_content).ok();
177 let local_var_error = ResponseContent {
178 status: local_var_status,
179 content: local_var_content,
180 entity: local_var_entity,
181 };
182 Err(Error::ResponseError(local_var_error))
183 }
184 }
185
186 async fn delete_user<'a>(
187 &self,
188 org_id: &'a str,
189 id: &'a str,
190 org_user_id: &'a str,
191 ) -> Result<(), Error<DeleteUserError>> {
192 let local_var_configuration = &self.configuration;
193
194 let local_var_client = &local_var_configuration.client;
195
196 let local_var_uri_str = format!(
197 "{}/organizations/{orgId}/groups/{id}/user/{orgUserId}",
198 local_var_configuration.base_path,
199 orgId = crate::apis::urlencode(org_id),
200 id = crate::apis::urlencode(id),
201 orgUserId = crate::apis::urlencode(org_user_id)
202 );
203 let mut local_var_req_builder =
204 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
205
206 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
207
208 let local_var_resp = local_var_req_builder.send().await?;
209
210 let local_var_status = local_var_resp.status();
211 let local_var_content = local_var_resp.text().await?;
212
213 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
214 Ok(())
215 } else {
216 let local_var_entity: Option<DeleteUserError> =
217 serde_json::from_str(&local_var_content).ok();
218 let local_var_error = ResponseContent {
219 status: local_var_status,
220 content: local_var_content,
221 entity: local_var_entity,
222 };
223 Err(Error::ResponseError(local_var_error))
224 }
225 }
226
227 async fn get<'a>(
228 &self,
229 org_id: &'a str,
230 id: &'a str,
231 ) -> Result<models::GroupResponseModel, Error<GetError>> {
232 let local_var_configuration = &self.configuration;
233
234 let local_var_client = &local_var_configuration.client;
235
236 let local_var_uri_str = format!(
237 "{}/organizations/{orgId}/groups/{id}",
238 local_var_configuration.base_path,
239 orgId = crate::apis::urlencode(org_id),
240 id = crate::apis::urlencode(id)
241 );
242 let mut local_var_req_builder =
243 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
244
245 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
246
247 let local_var_resp = local_var_req_builder.send().await?;
248
249 let local_var_status = local_var_resp.status();
250 let local_var_content_type = local_var_resp
251 .headers()
252 .get("content-type")
253 .and_then(|v| v.to_str().ok())
254 .unwrap_or("application/octet-stream");
255 let local_var_content_type = super::ContentType::from(local_var_content_type);
256 let local_var_content = local_var_resp.text().await?;
257
258 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
259 match local_var_content_type {
260 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
261 ContentType::Text => {
262 return Err(Error::from(serde_json::Error::custom(
263 "Received `text/plain` content type response that cannot be converted to `models::GroupResponseModel`",
264 )));
265 }
266 ContentType::Unsupported(local_var_unknown_type) => {
267 return Err(Error::from(serde_json::Error::custom(format!(
268 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::GroupResponseModel`"
269 ))));
270 }
271 }
272 } else {
273 let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
274 let local_var_error = ResponseContent {
275 status: local_var_status,
276 content: local_var_content,
277 entity: local_var_entity,
278 };
279 Err(Error::ResponseError(local_var_error))
280 }
281 }
282
283 async fn get_details<'a>(
284 &self,
285 org_id: &'a str,
286 id: &'a str,
287 ) -> Result<models::GroupDetailsResponseModel, Error<GetDetailsError>> {
288 let local_var_configuration = &self.configuration;
289
290 let local_var_client = &local_var_configuration.client;
291
292 let local_var_uri_str = format!(
293 "{}/organizations/{orgId}/groups/{id}/details",
294 local_var_configuration.base_path,
295 orgId = crate::apis::urlencode(org_id),
296 id = crate::apis::urlencode(id)
297 );
298 let mut local_var_req_builder =
299 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
300
301 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
302
303 let local_var_resp = local_var_req_builder.send().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 `models::GroupDetailsResponseModel`",
320 )));
321 }
322 ContentType::Unsupported(local_var_unknown_type) => {
323 return Err(Error::from(serde_json::Error::custom(format!(
324 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::GroupDetailsResponseModel`"
325 ))));
326 }
327 }
328 } else {
329 let local_var_entity: Option<GetDetailsError> =
330 serde_json::from_str(&local_var_content).ok();
331 let local_var_error = ResponseContent {
332 status: local_var_status,
333 content: local_var_content,
334 entity: local_var_entity,
335 };
336 Err(Error::ResponseError(local_var_error))
337 }
338 }
339
340 async fn get_organization_group_details<'a>(
341 &self,
342 org_id: uuid::Uuid,
343 ) -> Result<
344 models::GroupDetailsResponseModelListResponseModel,
345 Error<GetOrganizationGroupDetailsError>,
346 > {
347 let local_var_configuration = &self.configuration;
348
349 let local_var_client = &local_var_configuration.client;
350
351 let local_var_uri_str = format!(
352 "{}/organizations/{orgId}/groups/details",
353 local_var_configuration.base_path,
354 orgId = org_id
355 );
356 let mut local_var_req_builder =
357 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
358
359 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
360
361 let local_var_resp = local_var_req_builder.send().await?;
362
363 let local_var_status = local_var_resp.status();
364 let local_var_content_type = local_var_resp
365 .headers()
366 .get("content-type")
367 .and_then(|v| v.to_str().ok())
368 .unwrap_or("application/octet-stream");
369 let local_var_content_type = super::ContentType::from(local_var_content_type);
370 let local_var_content = local_var_resp.text().await?;
371
372 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
373 match local_var_content_type {
374 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
375 ContentType::Text => {
376 return Err(Error::from(serde_json::Error::custom(
377 "Received `text/plain` content type response that cannot be converted to `models::GroupDetailsResponseModelListResponseModel`",
378 )));
379 }
380 ContentType::Unsupported(local_var_unknown_type) => {
381 return Err(Error::from(serde_json::Error::custom(format!(
382 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::GroupDetailsResponseModelListResponseModel`"
383 ))));
384 }
385 }
386 } else {
387 let local_var_entity: Option<GetOrganizationGroupDetailsError> =
388 serde_json::from_str(&local_var_content).ok();
389 let local_var_error = ResponseContent {
390 status: local_var_status,
391 content: local_var_content,
392 entity: local_var_entity,
393 };
394 Err(Error::ResponseError(local_var_error))
395 }
396 }
397
398 async fn get_organization_groups<'a>(
399 &self,
400 org_id: uuid::Uuid,
401 ) -> Result<models::GroupResponseModelListResponseModel, Error<GetOrganizationGroupsError>>
402 {
403 let local_var_configuration = &self.configuration;
404
405 let local_var_client = &local_var_configuration.client;
406
407 let local_var_uri_str = format!(
408 "{}/organizations/{orgId}/groups",
409 local_var_configuration.base_path,
410 orgId = org_id
411 );
412 let mut local_var_req_builder =
413 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
414
415 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
416
417 let local_var_resp = local_var_req_builder.send().await?;
418
419 let local_var_status = local_var_resp.status();
420 let local_var_content_type = local_var_resp
421 .headers()
422 .get("content-type")
423 .and_then(|v| v.to_str().ok())
424 .unwrap_or("application/octet-stream");
425 let local_var_content_type = super::ContentType::from(local_var_content_type);
426 let local_var_content = local_var_resp.text().await?;
427
428 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
429 match local_var_content_type {
430 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
431 ContentType::Text => {
432 return Err(Error::from(serde_json::Error::custom(
433 "Received `text/plain` content type response that cannot be converted to `models::GroupResponseModelListResponseModel`",
434 )));
435 }
436 ContentType::Unsupported(local_var_unknown_type) => {
437 return Err(Error::from(serde_json::Error::custom(format!(
438 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::GroupResponseModelListResponseModel`"
439 ))));
440 }
441 }
442 } else {
443 let local_var_entity: Option<GetOrganizationGroupsError> =
444 serde_json::from_str(&local_var_content).ok();
445 let local_var_error = ResponseContent {
446 status: local_var_status,
447 content: local_var_content,
448 entity: local_var_entity,
449 };
450 Err(Error::ResponseError(local_var_error))
451 }
452 }
453
454 async fn get_users<'a>(
455 &self,
456 org_id: &'a str,
457 id: &'a str,
458 ) -> Result<Vec<uuid::Uuid>, Error<GetUsersError>> {
459 let local_var_configuration = &self.configuration;
460
461 let local_var_client = &local_var_configuration.client;
462
463 let local_var_uri_str = format!(
464 "{}/organizations/{orgId}/groups/{id}/users",
465 local_var_configuration.base_path,
466 orgId = crate::apis::urlencode(org_id),
467 id = crate::apis::urlencode(id)
468 );
469 let mut local_var_req_builder =
470 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
471
472 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
473
474 let local_var_resp = local_var_req_builder.send().await?;
475
476 let local_var_status = local_var_resp.status();
477 let local_var_content_type = local_var_resp
478 .headers()
479 .get("content-type")
480 .and_then(|v| v.to_str().ok())
481 .unwrap_or("application/octet-stream");
482 let local_var_content_type = super::ContentType::from(local_var_content_type);
483 let local_var_content = local_var_resp.text().await?;
484
485 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
486 match local_var_content_type {
487 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
488 ContentType::Text => {
489 return Err(Error::from(serde_json::Error::custom(
490 "Received `text/plain` content type response that cannot be converted to `Vec<uuid::Uuid>`",
491 )));
492 }
493 ContentType::Unsupported(local_var_unknown_type) => {
494 return Err(Error::from(serde_json::Error::custom(format!(
495 "Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec<uuid::Uuid>`"
496 ))));
497 }
498 }
499 } else {
500 let local_var_entity: Option<GetUsersError> =
501 serde_json::from_str(&local_var_content).ok();
502 let local_var_error = ResponseContent {
503 status: local_var_status,
504 content: local_var_content,
505 entity: local_var_entity,
506 };
507 Err(Error::ResponseError(local_var_error))
508 }
509 }
510
511 async fn post<'a>(
512 &self,
513 org_id: uuid::Uuid,
514 group_request_model: Option<models::GroupRequestModel>,
515 ) -> Result<models::GroupResponseModel, Error<PostError>> {
516 let local_var_configuration = &self.configuration;
517
518 let local_var_client = &local_var_configuration.client;
519
520 let local_var_uri_str = format!(
521 "{}/organizations/{orgId}/groups",
522 local_var_configuration.base_path,
523 orgId = org_id
524 );
525 let mut local_var_req_builder =
526 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
527
528 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
529 local_var_req_builder = local_var_req_builder.json(&group_request_model);
530
531 let local_var_resp = local_var_req_builder.send().await?;
532
533 let local_var_status = local_var_resp.status();
534 let local_var_content_type = local_var_resp
535 .headers()
536 .get("content-type")
537 .and_then(|v| v.to_str().ok())
538 .unwrap_or("application/octet-stream");
539 let local_var_content_type = super::ContentType::from(local_var_content_type);
540 let local_var_content = local_var_resp.text().await?;
541
542 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
543 match local_var_content_type {
544 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
545 ContentType::Text => {
546 return Err(Error::from(serde_json::Error::custom(
547 "Received `text/plain` content type response that cannot be converted to `models::GroupResponseModel`",
548 )));
549 }
550 ContentType::Unsupported(local_var_unknown_type) => {
551 return Err(Error::from(serde_json::Error::custom(format!(
552 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::GroupResponseModel`"
553 ))));
554 }
555 }
556 } else {
557 let local_var_entity: Option<PostError> = serde_json::from_str(&local_var_content).ok();
558 let local_var_error = ResponseContent {
559 status: local_var_status,
560 content: local_var_content,
561 entity: local_var_entity,
562 };
563 Err(Error::ResponseError(local_var_error))
564 }
565 }
566
567 async fn put<'a>(
568 &self,
569 org_id: uuid::Uuid,
570 id: uuid::Uuid,
571 group_request_model: Option<models::GroupRequestModel>,
572 ) -> Result<models::GroupResponseModel, Error<PutError>> {
573 let local_var_configuration = &self.configuration;
574
575 let local_var_client = &local_var_configuration.client;
576
577 let local_var_uri_str = format!(
578 "{}/organizations/{orgId}/groups/{id}",
579 local_var_configuration.base_path,
580 orgId = org_id,
581 id = id
582 );
583 let mut local_var_req_builder =
584 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
585
586 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
587 local_var_req_builder = local_var_req_builder.json(&group_request_model);
588
589 let local_var_resp = local_var_req_builder.send().await?;
590
591 let local_var_status = local_var_resp.status();
592 let local_var_content_type = local_var_resp
593 .headers()
594 .get("content-type")
595 .and_then(|v| v.to_str().ok())
596 .unwrap_or("application/octet-stream");
597 let local_var_content_type = super::ContentType::from(local_var_content_type);
598 let local_var_content = local_var_resp.text().await?;
599
600 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
601 match local_var_content_type {
602 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
603 ContentType::Text => {
604 return Err(Error::from(serde_json::Error::custom(
605 "Received `text/plain` content type response that cannot be converted to `models::GroupResponseModel`",
606 )));
607 }
608 ContentType::Unsupported(local_var_unknown_type) => {
609 return Err(Error::from(serde_json::Error::custom(format!(
610 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::GroupResponseModel`"
611 ))));
612 }
613 }
614 } else {
615 let local_var_entity: Option<PutError> = serde_json::from_str(&local_var_content).ok();
616 let local_var_error = ResponseContent {
617 status: local_var_status,
618 content: local_var_content,
619 entity: local_var_entity,
620 };
621 Err(Error::ResponseError(local_var_error))
622 }
623 }
624}
625
626#[derive(Debug, Clone, Serialize, Deserialize)]
628#[serde(untagged)]
629pub enum BulkDeleteError {
630 UnknownValue(serde_json::Value),
631}
632#[derive(Debug, Clone, Serialize, Deserialize)]
634#[serde(untagged)]
635pub enum DeleteError {
636 UnknownValue(serde_json::Value),
637}
638#[derive(Debug, Clone, Serialize, Deserialize)]
640#[serde(untagged)]
641pub enum DeleteUserError {
642 UnknownValue(serde_json::Value),
643}
644#[derive(Debug, Clone, Serialize, Deserialize)]
646#[serde(untagged)]
647pub enum GetError {
648 UnknownValue(serde_json::Value),
649}
650#[derive(Debug, Clone, Serialize, Deserialize)]
652#[serde(untagged)]
653pub enum GetDetailsError {
654 UnknownValue(serde_json::Value),
655}
656#[derive(Debug, Clone, Serialize, Deserialize)]
658#[serde(untagged)]
659pub enum GetOrganizationGroupDetailsError {
660 UnknownValue(serde_json::Value),
661}
662#[derive(Debug, Clone, Serialize, Deserialize)]
664#[serde(untagged)]
665pub enum GetOrganizationGroupsError {
666 UnknownValue(serde_json::Value),
667}
668#[derive(Debug, Clone, Serialize, Deserialize)]
670#[serde(untagged)]
671pub enum GetUsersError {
672 UnknownValue(serde_json::Value),
673}
674#[derive(Debug, Clone, Serialize, Deserialize)]
676#[serde(untagged)]
677pub enum PostError {
678 UnknownValue(serde_json::Value),
679}
680#[derive(Debug, Clone, Serialize, Deserialize)]
682#[serde(untagged)]
683pub enum PutError {
684 UnknownValue(serde_json::Value),
685}