use anyhow::Result;
use serde_json::Value;
use std::collections::HashMap;
use super::{NotificationProcessor, NotificationRegistry, OperationType, ProcessingResult};
pub struct NotificationHandler {
registry: NotificationRegistry,
}
impl NotificationHandler {
pub fn from_config(
notification_schema: Option<&HashMap<String, crate::configuration::EventSchema>>,
) -> Self {
let registry = if let Some(schemas) = notification_schema {
NotificationRegistry::from_config(schemas)
} else {
NotificationRegistry::new()
};
Self { registry }
}
pub fn process_request(
&self,
event_type: &str,
request_params: &HashMap<String, Value>,
payload: &Option<serde_json::Value>,
operation: OperationType,
) -> Result<ProcessingResult> {
let processor = NotificationProcessor::new(&self.registry);
processor.process_request_with_values(event_type, request_params, payload, operation)
}
pub fn get_identifier_keys(&self, event_type: &str) -> Result<Vec<String>> {
self.registry.get_identifier_keys(event_type)
}
pub fn get_required_identifier_keys(&self, event_type: &str) -> Result<Vec<String>> {
self.registry.get_required_identifier_keys(event_type)
}
pub fn get_whole_schema(&self) -> &HashMap<String, crate::configuration::EventSchema> {
self.registry.get_whole_schema()
}
}