use std::{fmt::Display, future::Future};
use pretix_webhook_events::WebhookEvent;
pub trait WebhookHandler: Send + Sync + 'static {
type Error: Display + Send + Sync + 'static;
fn handle(&self, event: WebhookEvent) -> impl Future<Output = Result<(), Self::Error>> + Send;
}
impl<F, Fut, E> WebhookHandler for F
where
F: Fn(WebhookEvent) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<(), E>> + Send,
E: Display + Send + Sync + 'static,
{
type Error = E;
fn handle(&self, event: WebhookEvent) -> impl Future<Output = Result<(), Self::Error>> + Send {
(self)(event)
}
}