use crate::models::{
DataStream, StreamDescriptor, StreamFetchRequest, StreamReadings, StreamStatusEvents,
};
pub type BackendError = Box<dyn std::error::Error + Send + Sync>;
#[async_trait::async_trait]
pub trait SourceBackend: Send + Sync + 'static {
fn source_system(&self) -> &str;
fn rediscover_every_cycle(&self) -> bool {
false
}
async fn discover_streams(&self) -> Result<Vec<StreamDescriptor>, BackendError>;
async fn fetch_readings(
&self,
requests: &[StreamFetchRequest],
) -> Result<Vec<StreamReadings>, BackendError>;
async fn fetch_status_events(
&self,
_streams: &[DataStream],
) -> Result<Vec<StreamStatusEvents>, BackendError> {
Ok(Vec::new())
}
async fn handle_command(
&self,
command: &str,
_payload: Option<serde_json::Value>,
) -> Result<serde_json::Value, BackendError> {
Err(format!("Unknown command: {command}").into())
}
}