use crate::meta::Meta;
use crate::service::{Service, ServiceStatus, Services};
use crate::{MetaEvent, OneselfRx, ServiceEvent, WatchRx};
use std::collections::HashMap;
use std::error::Error;
pub trait MetaDetector {
fn register(&mut self) -> impl Future<Output = Result<(), Box<dyn Error + 'static + Send>>>;
fn unregister(&mut self) -> impl Future<Output = Result<(), Box<dyn Error + 'static + Send>>>;
fn fetch(
&mut self,
) -> impl Future<Output = Result<Option<Meta>, Box<dyn Error + 'static + Send>>>;
fn fetch_all(
&mut self,
) -> impl Future<Output = Result<Vec<Meta>, Box<dyn Error + 'static + Send>>>;
fn watch(
&mut self,
) -> impl Future<Output = Result<WatchRx<MetaEvent>, Box<dyn Error + 'static + Send>>>;
fn watch_all(
&mut self,
) -> impl Future<Output = Result<WatchRx<MetaEvent>, Box<dyn Error + 'static + Send>>>;
}
pub trait Detector {
fn service(&self) -> &Service;
fn id(&self) -> Option<u32> {
self.service().key.id()
}
fn status(&self) -> ServiceStatus;
fn registered(&self) -> bool {
self.status().registered()
}
fn unregistered(&self) -> bool {
self.status().unregistered()
}
fn register(&mut self) -> impl Future<Output = Result<(), Box<dyn Error + 'static + Send>>>;
fn fetch(&mut self) -> impl Future<Output = Result<Services, Box<dyn Error + 'static + Send>>>;
fn fetch_all(
&mut self,
) -> impl Future<Output = Result<HashMap<String, Services>, Box<dyn Error + 'static + Send>>>;
fn watch(
&mut self,
) -> impl Future<Output = Result<WatchRx<ServiceEvent>, Box<dyn Error + 'static + Send>>>;
fn watch_all(
&mut self,
) -> impl Future<Output = Result<WatchRx<ServiceEvent>, Box<dyn Error + 'static + Send>>>;
fn oneself(&mut self) -> Option<OneselfRx>;
}