use crate::PushEntity;
use async_trait::async_trait;
#[async_trait]
pub trait UserSubscribeManage: 'static + Sync + Send {
type UserIdentify: UserMobId;
type PushData: PushEntity;
type Filter: SubscribeFilter;
type Err: From<<Self::Filter as SubscribeFilter>::Err>
+ std::error::Error
+ Send
+ Sync
+ 'static;
async fn fetch_subscribe_filter(
&self,
user_id: &Self::UserIdentify,
) -> Result<Self::Filter, Self::Err>;
async fn check_subscribed(
&self,
user_id: &Self::UserIdentify,
data_resource: &<Self::PushData as PushEntity>::Resource,
) -> Result<bool, Self::Err>;
async fn fetch_all_subscriber(
&self,
data_resource: &<Self::PushData as PushEntity>::Resource,
) -> Result<Vec<Self::UserIdentify>, Self::Err>;
}
pub trait SubscribeFilter: 'static + Send + Sync {
type Data: PushEntity;
type Err: 'static;
fn filter(&self, input: impl Iterator<Item = Self::Data>)
-> Result<Vec<Self::Data>, Self::Err>;
fn contains(&self, target: &<Self::Data as PushEntity>::Resource) -> Result<bool, Self::Err>;
}
pub trait UserMobId: Sized + Send + Sync + 'static {
type MobId: ToString + 'static + Send + Sync + Sized;
fn get_mob_id(&self) -> Self::MobId;
}