use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use crate::Status;
#[derive(Debug, Clone)]
pub struct NewComment {
pub commentable_type: &'static str,
pub commentable_id: i64,
pub parent_id: Option<i64>,
pub author_id: Option<i64>,
pub guest_email: Option<String>,
pub body: String,
}
type RuleFuture = Pin<Box<dyn Future<Output = laravel::Result<Status>> + Send>>;
#[derive(Clone)]
pub(crate) struct ModerationRule(pub(crate) Option<Arc<dyn Fn(NewComment) -> RuleFuture + Send + Sync>>);
impl ModerationRule {
pub(crate) fn new<F, Fut>(rule: F) -> Self
where
F: Fn(NewComment) -> Fut + Send + Sync + 'static,
Fut: Future<Output = laravel::Result<Status>> + Send + 'static,
{
Self(Some(Arc::new(move |comment| Box::pin(rule(comment)))))
}
}