cx_sdk/client/
notifications.rs

1// Copyright 2024 Coralogix Ltd.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::str::FromStr;
16
17use cx_api::proto::com::coralogixapis::notification_center::{
18    connectors::v1::{
19        BatchGetConnectorsRequest,
20        BatchGetConnectorsResponse,
21        CreateConnectorRequest,
22        CreateConnectorResponse,
23        DeleteConnectorRequest,
24        DeleteConnectorResponse,
25        GetConnectorRequest,
26        GetConnectorResponse,
27        GetConnectorTypeSummariesRequest,
28        GetConnectorTypeSummariesResponse,
29        ListConnectorsRequest,
30        ListConnectorsResponse,
31        ReplaceConnectorRequest,
32        ReplaceConnectorResponse,
33        connectors_service_client::ConnectorsServiceClient,
34    },
35    notifications::v1::{
36        TestConnectorConfigRequest,
37        TestConnectorConfigResponse,
38        TestDestinationRequest,
39        TestDestinationResponse,
40        TestExistingConnectorRequest,
41        TestExistingConnectorResponse,
42        TestExistingPresetRequest,
43        TestExistingPresetResponse,
44        TestPresetConfigRequest,
45        TestPresetConfigResponse,
46        TestRoutingConditionValidRequest,
47        TestRoutingConditionValidResponse,
48        TestTemplateRenderRequest,
49        TestTemplateRenderResponse,
50        testing_service_client::TestingServiceClient,
51    },
52    presets::v1::{
53        BatchGetPresetsRequest,
54        BatchGetPresetsResponse,
55        CreateCustomPresetRequest,
56        CreateCustomPresetResponse,
57        DeleteCustomPresetRequest,
58        DeleteCustomPresetResponse,
59        GetDefaultPresetSummaryRequest,
60        GetDefaultPresetSummaryResponse,
61        GetPresetRequest,
62        GetPresetResponse,
63        GetSystemDefaultPresetSummaryRequest,
64        GetSystemDefaultPresetSummaryResponse,
65        ListPresetSummariesRequest,
66        ListPresetSummariesResponse,
67        ReplaceCustomPresetRequest,
68        ReplaceCustomPresetResponse,
69        SetPresetAsDefaultRequest,
70        SetPresetAsDefaultResponse,
71        presets_service_client::PresetsServiceClient,
72    },
73    routers::v1::{
74        BatchGetGlobalRoutersRequest,
75        BatchGetGlobalRoutersResponse,
76        CreateOrReplaceGlobalRouterRequest,
77        CreateOrReplaceGlobalRouterResponse,
78        DeleteGlobalRouterRequest,
79        DeleteGlobalRouterResponse,
80        GetGlobalRouterRequest,
81        GetGlobalRouterResponse,
82        ListGlobalRoutersRequest,
83        ListGlobalRoutersResponse,
84        global_routers_service_client::GlobalRoutersServiceClient,
85    },
86};
87
88pub use cx_api::proto::com::coralogixapis::notification_center::{
89    ConditionType,
90    ConfigOverrides,
91    ConnectorConfigField,
92    ConnectorType,
93    EntityType,
94    MatchEntityTypeAndSubTypeCondition,
95    MatchEntityTypeCondition,
96    MessageConfig,
97    MessageConfigField,
98    TemplatedConnectorConfigField,
99    condition_type,
100    connectors::v1::{
101        Connector,
102        ConnectorConfig,
103        EntityTypeConfigOverrides,
104    },
105    notifications::v1::{
106        TestResult,
107        test_result,
108        test_template_render_result,
109    },
110    presets::v1::Preset,
111    presets::v1::PresetType,
112    routers::v1::GlobalRouter,
113    routing::{
114        RoutingRule,
115        RoutingTarget,
116    },
117};
118
119use tokio::sync::Mutex;
120use tonic::{
121    metadata::MetadataMap,
122    transport::{
123        Channel,
124        ClientTlsConfig,
125        Endpoint,
126    },
127};
128
129use crate::{
130    CoralogixRegion,
131    auth::AuthContext,
132    error::{
133        Result,
134        SdkApiError,
135        SdkError,
136    },
137    metadata::CallProperties,
138    util::make_request_with_metadata,
139};
140
141const NOTIFICATIONS_FEATURE_GROUP_ID: &str = "notifications";
142
143/// A client for interacting with the Coralogix Notification Center APIs.
144pub struct NotificationsClient {
145    metadata_map: MetadataMap,
146    connectors_client: Mutex<ConnectorsServiceClient<Channel>>,
147    presets_client: Mutex<PresetsServiceClient<Channel>>,
148    global_routers_client: Mutex<GlobalRoutersServiceClient<Channel>>,
149    testing_client: Mutex<TestingServiceClient<Channel>>,
150}
151
152impl NotificationsClient {
153    /// Creates a new client for the Notification Center.
154    /// # Arguments
155    /// * `auth_context` - The [`AuthContext`] to use for authentication.
156    /// * `region` - The [`CoralogixRegion`] to connect to.
157    pub fn new(auth_context: AuthContext, region: CoralogixRegion) -> Result<Self> {
158        let channel: Channel = Endpoint::from_str(region.grpc_endpoint().as_str())?
159            .tls_config(ClientTlsConfig::new().with_native_roots())?
160            .connect_lazy();
161        let request_metadata: CallProperties = (&auth_context.team_level_api_key).into();
162        Ok(Self {
163            metadata_map: request_metadata.to_metadata_map(),
164            connectors_client: Mutex::new(ConnectorsServiceClient::new(channel.clone())),
165            presets_client: Mutex::new(PresetsServiceClient::new(channel.clone())),
166            global_routers_client: Mutex::new(GlobalRoutersServiceClient::new(channel.clone())),
167            testing_client: Mutex::new(TestingServiceClient::new(channel)),
168        })
169    }
170
171    /// Get a connector by ID.
172    /// # Arguments
173    /// * `connector_id` - The ID of the connector to get.
174    pub async fn get_connector(&self, connector_id: String) -> Result<GetConnectorResponse> {
175        let request = make_request_with_metadata(
176            GetConnectorRequest {
177                id: connector_id,
178                ..Default::default()
179            },
180            &self.metadata_map,
181        );
182        {
183            let mut client = self.connectors_client.lock().await.clone();
184            client
185                .get_connector(request)
186                .await
187                .map(|r| r.into_inner())
188                .map_err(
189                    |status| SdkError::ApiError(SdkApiError {
190                        status,
191                        endpoint: "/com.coralogixapis.notification_center.connectors.v1.ConnectorsService/GetConnector".into(),
192                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
193                    },
194                ))
195        }
196    }
197
198    /// List all connectors.
199    /// # Arguments
200    /// * `connector_type` - The [`ConnectorType`] to filter by.
201    pub async fn list_connectors(
202        &self,
203        connector_type: ConnectorType,
204    ) -> Result<ListConnectorsResponse> {
205        let request = make_request_with_metadata(
206            ListConnectorsRequest {
207                connector_type: connector_type.into(),
208            },
209            &self.metadata_map,
210        );
211        {
212            let mut client = self.connectors_client.lock().await.clone();
213
214            client
215                .list_connectors(request)
216                .await
217                .map(|r| r.into_inner())
218                .map_err(
219                    |status| SdkError::ApiError(SdkApiError {
220                        status,
221                        endpoint: "/com.coralogixapis.notification_center.connectors.v1.ConnectorsService/ListConnectors".into(),
222                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
223                    },
224                ))
225        }
226    }
227
228    /// Create a new connector.
229    /// # Arguments
230    /// * `connector` - The [`Connector`] to create.
231    pub async fn create_connector(&self, connector: Connector) -> Result<CreateConnectorResponse> {
232        let request = make_request_with_metadata(
233            CreateConnectorRequest {
234                connector: Some(connector),
235            },
236            &self.metadata_map,
237        );
238        {
239            let mut client = self.connectors_client.lock().await.clone();
240
241            client
242                .create_connector(request)
243                .await
244                .map(|r| r.into_inner())
245                .map_err(
246                    |status| SdkError::ApiError(SdkApiError {
247                        status,
248                        endpoint: "/com.coralogixapis.notification_center.connectors.v1.ConnectorsService/CreateConnector".into(),
249                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
250                    },
251                ))
252        }
253    }
254
255    /// Replace an existing connector.
256    /// # Arguments
257    /// * `connector` - The [`Connector`] to replace.
258    pub async fn replace_connector(
259        &self,
260        connector: Connector,
261    ) -> Result<ReplaceConnectorResponse> {
262        let request = make_request_with_metadata(
263            ReplaceConnectorRequest {
264                connector: Some(connector),
265            },
266            &self.metadata_map,
267        );
268        {
269            let mut client = self.connectors_client.lock().await.clone();
270
271            client
272                .replace_connector(request)
273                .await
274                .map(|r| r.into_inner())
275                .map_err(
276                    |status| SdkError::ApiError(SdkApiError {
277                        status,
278                        endpoint: "/com.coralogixapis.notification_center.connectors.v1.ConnectorsService/ReplaceConnector".into(),
279                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
280                    },
281                ))
282        }
283    }
284
285    /// Delete a connector by ID.
286    /// # Arguments
287    /// * `connector_id` - The ID of the connector to delete.
288    pub async fn delete_connector(&self, connector_id: String) -> Result<DeleteConnectorResponse> {
289        let request = make_request_with_metadata(
290            DeleteConnectorRequest {
291                id: connector_id,
292                ..Default::default()
293            },
294            &self.metadata_map,
295        );
296        {
297            let mut client = self.connectors_client.lock().await.clone();
298
299            client
300                .delete_connector(request)
301                .await
302                .map(|r| r.into_inner())
303                .map_err(
304                    |status| SdkError::ApiError(SdkApiError {
305                        status,
306                        endpoint: "/com.coralogixapis.notification_center.connectors.v1.ConnectorsService/DeleteConnector".into(),
307                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
308                    },
309                ))
310        }
311    }
312
313    /// Batch get connectors by ID.
314    /// # Arguments
315    /// * `connector_ids` - The IDs of the connectors to get.
316    pub async fn batch_get_connectors(
317        &self,
318        connector_ids: Vec<String>,
319    ) -> Result<BatchGetConnectorsResponse> {
320        let request = make_request_with_metadata(
321            BatchGetConnectorsRequest {
322                connector_ids,
323                ..Default::default()
324            },
325            &self.metadata_map,
326        );
327        {
328            let mut client = self.connectors_client.lock().await.clone();
329
330            client
331                .batch_get_connectors(request)
332                .await
333                .map(|r| r.into_inner())
334                .map_err(
335                    |status| SdkError::ApiError(SdkApiError {
336                        status,
337                        endpoint: "/com.coralogixapis.notification_center.connectors.v1.ConnectorsService/BatchGetConnectors".into(),
338                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
339                    },
340                ))
341        }
342    }
343
344    /// Get summaries of connector types.
345    pub async fn get_connector_type_summaries(&self) -> Result<GetConnectorTypeSummariesResponse> {
346        let request =
347            make_request_with_metadata(GetConnectorTypeSummariesRequest {}, &self.metadata_map);
348        {
349            let mut client = self.connectors_client.lock().await.clone();
350
351            client
352                .get_connector_type_summaries(request)
353                .await
354                .map(|r| r.into_inner())
355                .map_err(
356                    |status| SdkError::ApiError(SdkApiError {
357                        status,
358                        endpoint: "/com.coralogixapis.notification_center.connectors.v1.ConnectorsService/GetConnectorTypeSummaries".into(),
359                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
360                    },
361                ))
362        }
363    }
364
365    /// Create a new custom preset.
366    /// # Arguments
367    /// * `preset` - The [`Preset`] to create.
368    pub async fn create_custom_preset(&self, preset: Preset) -> Result<CreateCustomPresetResponse> {
369        let request = make_request_with_metadata(
370            CreateCustomPresetRequest {
371                preset: Some(preset),
372            },
373            &self.metadata_map,
374        );
375        {
376            let mut client = self.presets_client.lock().await.clone();
377
378            client
379                .create_custom_preset(request)
380                .await
381                .map(|r| r.into_inner())
382                .map_err(
383                    |status| SdkError::ApiError(SdkApiError {
384                        status,
385                        endpoint: "/com.coralogixapis.notification_center.presets.v1.PresetsService/CreateCustomPreset".into(),
386                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
387                    },
388                ))
389        }
390    }
391
392    /// Replace an existing custom preset.
393    /// # Arguments
394    /// * `preset` - The [`Preset`] to replace.
395    pub async fn replace_custom_preset(
396        &self,
397        preset: Preset,
398    ) -> Result<ReplaceCustomPresetResponse> {
399        let request = make_request_with_metadata(
400            ReplaceCustomPresetRequest {
401                preset: Some(preset),
402            },
403            &self.metadata_map,
404        );
405        {
406            let mut client = self.presets_client.lock().await.clone();
407
408            client
409                .replace_custom_preset(request)
410                .await
411                .map(|r| r.into_inner())
412                .map_err(
413                    |status| SdkError::ApiError(SdkApiError {
414                        status,
415                        endpoint: "/com.coralogixapis.notification_center.presets.v1.PresetsService/ReplaceCustomPreset".into(),
416                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
417                    },
418                ))
419        }
420    }
421
422    /// Delete a custom preset by ID.
423    /// # Arguments
424    /// * `id` - The ID of the preset to delete.
425    pub async fn delete_custom_preset(&self, id: String) -> Result<DeleteCustomPresetResponse> {
426        let request = make_request_with_metadata(
427            DeleteCustomPresetRequest {
428                id,
429                ..Default::default()
430            },
431            &self.metadata_map,
432        );
433        {
434            let mut client = self.presets_client.lock().await.clone();
435
436            client
437                .delete_custom_preset(request)
438                .await
439                .map(|r| r.into_inner())
440                .map_err(
441                    |status| SdkError::ApiError(SdkApiError {
442                        status,
443                        endpoint: "/com.coralogixapis.notification_center.presets.v1.PresetsService/DeleteCustomPreset".into(),
444                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
445                    },
446                ))
447        }
448    }
449
450    /// Set a preset as the default.
451    /// # Arguments
452    /// * `id` - The user-facing ID of the preset to set as the default.
453    pub async fn set_preset_as_default(&self, id: String) -> Result<SetPresetAsDefaultResponse> {
454        let request = make_request_with_metadata(
455            SetPresetAsDefaultRequest {
456                id,
457                ..Default::default()
458            },
459            &self.metadata_map,
460        );
461
462        let mut client = self.presets_client.lock().await.clone();
463
464        client
465            .set_preset_as_default(request)
466            .await
467            .map(|r| r.into_inner())
468            .map_err(|status| {
469                SdkError::ApiError(SdkApiError {
470                    status,
471                    endpoint: "/com.coralogixapis.notification_center.presets.v1.PresetsService/SetPresetAsDefault".into(),
472                    feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into(),
473                })
474            })
475    }
476
477    /// Get a preset by ID.
478    /// # Arguments
479    /// * `id` - The ID of the preset to get.
480    pub async fn get_preset(&self, id: String) -> Result<GetPresetResponse> {
481        let request = make_request_with_metadata(
482            GetPresetRequest {
483                id,
484                ..Default::default()
485            },
486            &self.metadata_map,
487        );
488        {
489            let mut client = self.presets_client.lock().await.clone();
490
491            client
492                .get_preset(request)
493                .await
494                .map(|r| r.into_inner())
495                .map_err(
496                    |status| SdkError::ApiError(SdkApiError {
497                        status,
498                        endpoint: "/com.coralogixapis.notification_center.presets.v1.PresetsService/GetPreset".into(),
499                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
500                    },
501                ))
502        }
503    }
504
505    /// List summaries of presets.
506    /// # Arguments
507    /// * `connector_type` - The [`ConnectorType`] to list presets for.
508    /// * `entity_type` - The [`EntityType`] to list presets for.
509    pub async fn list_preset_summaries(
510        &self,
511        connector_type: Option<ConnectorType>,
512        entity_type: EntityType,
513    ) -> Result<ListPresetSummariesResponse> {
514        let request = make_request_with_metadata(
515            ListPresetSummariesRequest {
516                connector_type: connector_type.map(From::from),
517                entity_type: entity_type.into(),
518                ..Default::default()
519            },
520            &self.metadata_map,
521        );
522        {
523            let mut client = self.presets_client.lock().await.clone();
524
525            client
526                .list_preset_summaries(request)
527                .await
528                .map(|r| r.into_inner())
529                .map_err(
530                    |status| SdkError::ApiError(SdkApiError {
531                        status,
532                        endpoint: "/com.coralogixapis.notification_center.presets.v1.PresetsService/ListPresetSummaries".into(),
533                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
534                    },
535                ))
536        }
537    }
538
539    /// Batch get presets by ID.
540    /// # Arguments
541    /// * `preset_ids` - The IDs of the presets to get.
542    pub async fn batch_get_presets(
543        &self,
544        preset_ids: Vec<String>,
545    ) -> Result<BatchGetPresetsResponse> {
546        let request = make_request_with_metadata(
547            BatchGetPresetsRequest {
548                preset_ids,
549                ..Default::default()
550            },
551            &self.metadata_map,
552        );
553        {
554            let mut client = self.presets_client.lock().await.clone();
555
556            client
557                .batch_get_presets(request)
558                .await
559                .map(|r| r.into_inner())
560                .map_err(
561                    |status| SdkError::ApiError(SdkApiError {
562                        status,
563                        endpoint: "/com.coralogixapis.notification_center.presets.v1.PresetsService/BatchGetPresets".into(),
564                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
565                    },
566                ))
567        }
568    }
569
570    /// Get the default preset summary.
571    /// # Arguments
572    /// * `connector_type` - The [`ConnectorType`] to get the default preset summary for.
573    /// * `entity_type` - The [`EntityType`] to get the default preset summary for.
574    pub async fn get_default_preset_summary(
575        &self,
576        connector_type: ConnectorType,
577        entity_type: EntityType,
578    ) -> Result<GetDefaultPresetSummaryResponse> {
579        let request = make_request_with_metadata(
580            GetDefaultPresetSummaryRequest {
581                connector_type: connector_type.into(),
582                entity_type: entity_type.into(),
583                ..Default::default()
584            },
585            &self.metadata_map,
586        );
587        {
588            let mut client = self.presets_client.lock().await.clone();
589
590            client
591                .get_default_preset_summary(request)
592                .await
593                .map(|r| r.into_inner())
594                .map_err(
595                    |status| SdkError::ApiError(SdkApiError {
596                        status,
597                        endpoint: "/com.coralogixapis.notification_center.presets.v1.PresetsService/GetDefaultPresetSummary".into(),
598                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
599                    },
600                ))
601        }
602    }
603
604    /// Get the system default preset summary.
605    /// # Arguments
606    /// * `connector_type` - The [`ConnectorType`] to get the system default preset summary for.
607    /// * `entity_type` - The [`EntityType`] to get the system default preset summary for.
608    pub async fn get_system_default_preset_summary(
609        &self,
610        connector_type: ConnectorType,
611        entity_type: EntityType,
612    ) -> Result<GetSystemDefaultPresetSummaryResponse> {
613        let request = make_request_with_metadata(
614            GetSystemDefaultPresetSummaryRequest {
615                connector_type: connector_type as i32,
616                entity_type: entity_type.into(),
617                ..Default::default()
618            },
619            &self.metadata_map,
620        );
621        {
622            let mut client = self.presets_client.lock().await.clone();
623
624            client
625                .get_system_default_preset_summary(request)
626                .await
627                .map(|r| r.into_inner())
628                .map_err(
629                    |status| SdkError::ApiError(SdkApiError {
630                        status,
631                        endpoint: "/com.coralogixapis.notification_center.presets.v1.PresetsService/GetSystemDefaultPresetSummary".into(),
632                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
633                    },
634                ))
635        }
636    }
637
638    /// Create or replace a global router.
639    /// # Arguments
640    /// * `global_router` - The [`GlobalRouter`] to create or replace.
641    pub async fn create_or_replace_global_router(
642        &self,
643        global_router: GlobalRouter,
644    ) -> Result<CreateOrReplaceGlobalRouterResponse> {
645        let request = make_request_with_metadata(
646            CreateOrReplaceGlobalRouterRequest {
647                router: Some(global_router),
648            },
649            &self.metadata_map,
650        );
651        let mut client = self.global_routers_client.lock().await.clone();
652
653        client
654            .create_or_replace_global_router(request)
655            .await
656            .map(|r| r.into_inner())
657            .map_err(|status| SdkError::ApiError(SdkApiError {
658                status,
659                endpoint: "/com.coralogixapis.notification_center.routers.v1.GlobalRoutersService/CreateOrReplaceGlobalRouter".into(),
660                feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into(),
661            }))
662    }
663
664    /// Delete a global router by identifier.
665    /// # Arguments
666    /// * `id` - The identifier of the global router to delete.
667    pub async fn delete_global_router(&self, id: String) -> Result<DeleteGlobalRouterResponse> {
668        let request = make_request_with_metadata(
669            DeleteGlobalRouterRequest {
670                id,
671                ..Default::default()
672            },
673            &self.metadata_map,
674        );
675        let mut client = self.global_routers_client.lock().await.clone();
676
677        client
678            .delete_global_router(request)
679            .await
680            .map(|r| r.into_inner())
681            .map_err(|status| SdkError::ApiError(SdkApiError {
682                status,
683                endpoint: "/com.coralogixapis.notification_center.routers.v1.GlobalRoutersService/DeleteGlobalRouter".into(),
684                feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into(),
685            }))
686    }
687
688    /// Get a global router by identifier.
689    /// # Arguments
690    /// * `id` - The identifier of the global router to get.
691    pub async fn get_global_router(&self, id: String) -> Result<GetGlobalRouterResponse> {
692        let request = make_request_with_metadata(
693            GetGlobalRouterRequest {
694                id,
695                ..Default::default()
696            },
697            &self.metadata_map,
698        );
699        let mut client = self.global_routers_client.lock().await.clone();
700
701        client
702            .get_global_router(request)
703            .await
704            .map(|r| r.into_inner())
705            .map_err(|status| SdkError::ApiError(SdkApiError {
706                status,
707                endpoint: "/com.coralogixapis.notification_center.routers.v1.GlobalRoutersService/GetGlobalRouter".into(),
708                feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into(),
709            }))
710    }
711
712    /// List all global routers.
713    /// # Arguments
714    /// * `entity_type` - The [`EntityType`] to filter global routers by.
715    pub async fn list_global_routers(
716        &self,
717        entity_type: EntityType,
718    ) -> Result<ListGlobalRoutersResponse> {
719        let request = make_request_with_metadata(
720            ListGlobalRoutersRequest {
721                entity_type: Some(entity_type.into()),
722                ..Default::default()
723            },
724            &self.metadata_map,
725        );
726        let mut client = self.global_routers_client.lock().await.clone();
727
728        client
729            .list_global_routers(request)
730            .await
731            .map(|r| r.into_inner())
732            .map_err(|status| SdkError::ApiError(SdkApiError {
733                status,
734                endpoint: "/com.coralogixapis.notification_center.routers.v1.GlobalRoutersService/ListGlobalRouters".into(),
735                feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into(),
736            }))
737    }
738
739    /// Batch get global routers by identifiers.
740    /// # Arguments
741    /// * `ids` - The identifiers of the global routers to retrieve.
742    pub async fn batch_get_global_routers(
743        &self,
744        ids: Vec<String>,
745    ) -> Result<BatchGetGlobalRoutersResponse> {
746        let request = make_request_with_metadata(
747            BatchGetGlobalRoutersRequest {
748                global_router_ids: ids,
749                ..Default::default()
750            },
751            &self.metadata_map,
752        );
753        let mut client = self.global_routers_client.lock().await.clone();
754
755        client
756            .batch_get_global_routers(request)
757            .await
758            .map(|r| r.into_inner())
759            .map_err(|status| SdkError::ApiError(SdkApiError {
760                status,
761                endpoint: "/com.coralogixapis.notification_center.routers.v1.GlobalRoutersService/BatchGetGlobalRouters".into(),
762                feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into(),
763            }))
764    }
765
766    /// Test a connector configuration.
767    /// # Arguments
768    /// * `connector_type` - The [`ConnectorType`] to test.
769    /// * `connector_config_fields` - The [ConnectorConfigField]s to test with.
770    /// * `entity_type` - The [`EntityType`] to test with.
771    /// * `output_schema_id` - The id of the output schema to test with.
772    pub async fn test_connector_config(
773        &self,
774        connector_type: ConnectorType,
775        connector_config_fields: Vec<ConnectorConfigField>,
776        entity_type: EntityType,
777        output_schema_id: String,
778    ) -> Result<TestConnectorConfigResponse> {
779        let request = make_request_with_metadata(
780            TestConnectorConfigRequest {
781                r#type: connector_type.into(),
782                fields: connector_config_fields,
783                entity_type: Some(entity_type.into()),
784                output_schema_id,
785                ..Default::default()
786            },
787            &self.metadata_map,
788        );
789        {
790            let mut client = self.testing_client.lock().await.clone();
791
792            client
793                .test_connector_config(request)
794                .await
795                .map(|r| r.into_inner())
796                .map_err(
797                    |status| SdkError::ApiError(SdkApiError {
798                        status,
799                        endpoint: "/com.coralogixapis.notification_center.notifications.v1.TestingService/TestConnectorConfig".into(),
800                                                feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
801                    },
802                ))
803        }
804    }
805
806    /// Test an existing connector.
807    /// # Arguments
808    /// * `connector_id` - The id of the connector to test.
809    pub async fn test_existing_connector(
810        &self,
811        connector_id: String,
812        output_schema_id: String,
813    ) -> Result<TestExistingConnectorResponse> {
814        let request = make_request_with_metadata(
815            TestExistingConnectorRequest {
816                connector_id,
817                output_schema_id,
818                ..Default::default()
819            },
820            &self.metadata_map,
821        );
822        {
823            let mut client = self.testing_client.lock().await.clone();
824
825            client
826                .test_existing_connector(request)
827                .await
828                .map(|r| r.into_inner())
829                .map_err(
830                    |status| SdkError::ApiError(SdkApiError {
831                        status,
832                        endpoint: "/com.coralogixapis.notification_center.notifications.v1.TestingService/TestExistingConnector".into(),
833                                                feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
834                    },
835                ))
836        }
837    }
838
839    /// Test a preset configuration.
840    /// # Arguments
841    /// * `entity_type` - The entity type.
842    /// * `connector_id` - The ID for the connector to test.
843    /// * `parent_preset_id` - The ID of the preset's parent to test.
844    /// * `config_overrides` - The set of [`ConfigOverrides`] to apply.
845    pub async fn test_preset_config(
846        &self,
847        entity_type: EntityType,
848        connector_id: String,
849        parent_preset_id: String,
850        config_overrides: Vec<ConfigOverrides>,
851    ) -> Result<TestPresetConfigResponse> {
852        let request = make_request_with_metadata(
853            TestPresetConfigRequest {
854                entity_type: entity_type.into(),
855                connector_id,
856                parent_preset_id,
857                config_overrides,
858                ..Default::default()
859            },
860            &self.metadata_map,
861        );
862        {
863            let mut client = self.testing_client.lock().await.clone();
864
865            client
866                .test_preset_config(request)
867                .await
868                .map(|r| r.into_inner())
869                .map_err(
870                    |status| SdkError::ApiError(SdkApiError {
871                        status,
872                        endpoint: "/com.coralogixapis.notification_center.notifications.v1.TestingService/TestPreset".into(),
873                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
874                    },
875                ))
876        }
877    }
878
879    /// Test a preset configuration.
880    /// # Arguments
881    /// * `entity_type` - The entity type.
882    /// * `connector_id` - The ID for the connector to test.
883    /// * `preset_id` - The ID of the preset to test.
884    pub async fn test_existing_preset_config(
885        &self,
886        entity_type: EntityType,
887        connector_id: String,
888        preset_id: String,
889    ) -> Result<TestExistingPresetResponse> {
890        let request = make_request_with_metadata(
891            TestExistingPresetRequest {
892                entity_type: entity_type.into(),
893                connector_id,
894                preset_id,
895                ..Default::default()
896            },
897            &self.metadata_map,
898        );
899        {
900            let mut client = self.testing_client.lock().await.clone();
901
902            client
903                .test_existing_preset(request)
904                .await
905                .map(|r| r.into_inner())
906                .map_err(
907                    |status| SdkError::ApiError(SdkApiError {
908                        status,
909                        endpoint: "/com.coralogixapis.notification_center.notifications.v1.TestingService/TestExistingPreset".into(),
910                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
911                    },
912                ))
913        }
914    }
915
916    /// Test rendering a template.
917    /// # Arguments
918    /// * `entity_type` - The entity type to test with.
919    /// * `entity_sub_type` - The entity sub type to test with.
920    /// * `template` - The template to render.
921    pub async fn test_template_render(
922        &self,
923        entity_type: EntityType,
924        entity_sub_type: Option<String>,
925        template: String,
926    ) -> Result<TestTemplateRenderResponse> {
927        let request = make_request_with_metadata(
928            TestTemplateRenderRequest {
929                entity_type: entity_type.into(),
930                entity_sub_type,
931                template,
932                ..Default::default()
933            },
934            &self.metadata_map,
935        );
936        {
937            let mut client = self.testing_client.lock().await.clone();
938
939            client
940                .test_template_render(request)
941                .await
942                .map(|r| r.into_inner())
943                .map_err(
944                    |status| SdkError::ApiError(SdkApiError {
945                        status,
946                        endpoint: "/com.coralogixapis.notification_center.notifications.v1.TestingService/TestTemplateRender".into(),
947                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
948                    },
949                ))
950        }
951    }
952
953    /// Test a destination.
954    /// # Arguments
955    /// * `entity_type` - The entity type to test with.
956    /// * `connector_config_fields` - Connector configuration (templated).
957    /// * `preset_id` - Preset ID.
958    /// * `connector_id` - Connector ID.
959    /// * `message_config_fields` - Message configuration.
960    pub async fn test_destination(
961        &self,
962        entity_type: EntityType,
963        connector_config_fields: Vec<TemplatedConnectorConfigField>,
964        preset_id: String,
965        connector_id: String,
966        message_config_fields: Vec<MessageConfigField>,
967        output_schema_id: String,
968    ) -> Result<TestDestinationResponse> {
969        let request = make_request_with_metadata(
970            TestDestinationRequest {
971                entity_type: entity_type.into(),
972                connector_config_fields,
973                message_config_fields,
974                preset_id,
975                connector_id,
976                output_schema_id,
977                ..Default::default()
978            },
979            &self.metadata_map,
980        );
981        {
982            let mut client = self.testing_client.lock().await.clone();
983
984            client
985                .test_destination(request)
986                .await
987                .map(|r| r.into_inner())
988                .map_err(
989                    |status| SdkError::ApiError(SdkApiError {
990                        status,
991                        endpoint: "/com.coralogixapis.notification_center.notifications.v1.TestingService/TestDestination".into(),
992                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
993                    },
994                ))
995        }
996    }
997
998    /// Tests whether a routing condition is valid.
999    /// # Arguments
1000    /// * `entity_type` - The entity type to test with.
1001    /// * `template` - The template to render.
1002    pub async fn test_routing_condition_valid(
1003        &self,
1004        entity_type: EntityType,
1005        template: String,
1006    ) -> Result<TestRoutingConditionValidResponse> {
1007        let request = make_request_with_metadata(
1008            TestRoutingConditionValidRequest {
1009                entity_type: entity_type.into(),
1010                template,
1011                ..Default::default()
1012            },
1013            &self.metadata_map,
1014        );
1015        {
1016            let mut client = self.testing_client.lock().await.clone();
1017
1018            client
1019                .test_routing_condition_valid(request)
1020                .await
1021                .map(|r| r.into_inner())
1022                .map_err(
1023                    |status| SdkError::ApiError(SdkApiError {
1024                        status,
1025                        endpoint: "/com.coralogixapis.notification_center.notifications.v1.TestingService/TestRoutingConditionValid".into(),
1026                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
1027                    },
1028                ))
1029        }
1030    }
1031}