use std::sync::Arc;
use crate::bootstrap::infrastructure::Repositories;
use crate::config::settings::Settings;
#[cfg(not(feature = "webhook"))]
use crate::domain::services::noop_webhook_service::NoopWebhookService;
use crate::domain::services::webhook_service::WebhookService;
#[cfg(feature = "webhook")]
use crate::domain::services::webhook_service::WebhookServiceImpl;
#[cfg(feature = "webhook")]
use crate::infrastructure::services::webhook_sender_impl::WebhookSenderImpl;
pub(super) fn init_webhook_service(
#[cfg_attr(not(feature = "webhook"), allow(unused_variables))] repositories: &Repositories,
#[cfg_attr(not(feature = "webhook"), allow(unused_variables))] settings: &Settings,
http_client: &Arc<reqwest::Client>,
) -> Arc<dyn WebhookService> {
#[cfg(feature = "webhook")]
let webhook_sender: Arc<WebhookSenderImpl> = Arc::new(WebhookSenderImpl::new(
http_client.clone(),
std::time::Duration::from_secs(10),
));
#[cfg(feature = "webhook")]
let webhook_service: Arc<WebhookServiceImpl> = Arc::new(WebhookServiceImpl::new(
webhook_sender.clone(),
settings.webhook.secret().to_string(),
repositories.webhook_event_repo.clone(),
));
#[cfg(not(feature = "webhook"))]
let webhook_service: Arc<NoopWebhookService> = {
log::info!(
"webhook feature disabled, using NoopWebhookService — \
trigger_completion/trigger_failure are no-ops"
);
Arc::new(NoopWebhookService::new())
};
webhook_service
}