use crate::domain::{HookCallback, HookContext, HookInput, HookJSONOutput};
use crate::error::Result;
use crate::ports::secondary::{HookEvent, HookService};
use async_trait::async_trait;
use std::collections::HashMap;
pub struct CallbackHookService {
hooks: HashMap<String, HookCallback>,
}
impl CallbackHookService {
pub fn new(hooks: HashMap<String, HookCallback>) -> Self {
Self { hooks }
}
pub fn add_hook(&mut self, id: String, callback: HookCallback) {
self.hooks.insert(id, callback);
}
}
#[async_trait]
impl HookService for CallbackHookService {
async fn execute_hook(
&self,
_event: HookEvent,
_input: HookInput,
_context: HookContext,
) -> Result<HookJSONOutput> {
Ok(HookJSONOutput::Sync {
should_continue: Some(true),
suppress_output: None,
stop_reason: None,
decision: None,
system_message: None,
reason: None,
hook_specific_output: None,
})
}
}
pub struct NoOpHookService;
#[async_trait]
impl HookService for NoOpHookService {
async fn execute_hook(
&self,
_event: HookEvent,
_input: HookInput,
_context: HookContext,
) -> Result<HookJSONOutput> {
Ok(HookJSONOutput::Sync {
should_continue: Some(true),
suppress_output: None,
stop_reason: None,
decision: None,
system_message: None,
reason: None,
hook_specific_output: None,
})
}
}