use crate::core::error::Result;
use crate::core::types::{ChannelState, ChannelType, DeviceId, Message};
use async_trait::async_trait;
#[async_trait]
pub trait Channel: Send + Sync {
fn channel_type(&self) -> ChannelType;
async fn send(&self, message: Message) -> Result<()>;
async fn check_state(&self, target: &DeviceId) -> Result<ChannelState>;
async fn start(&self) -> Result<()>;
async fn start_with_handler(
&self,
_handler: std::sync::Arc<dyn MessageHandler>,
) -> Result<Option<tokio::task::JoinHandle<()>>> {
self.start().await?;
Ok(None)
}
async fn clear_handler(&self) -> Result<()> {
Ok(())
}
}
#[async_trait]
pub trait Storage: Send + Sync {
async fn save_message(&self, message: &Message) -> Result<()>;
async fn get_pending_messages(&self, device_id: &DeviceId) -> Result<Vec<Message>>;
async fn remove_message(&self, message_id: &uuid::Uuid) -> Result<()>;
async fn save_audit_log(&self, log: String) -> Result<()>;
async fn get_audit_logs(&self, limit: usize) -> Result<Vec<String>>;
async fn cleanup_old_data(&self, days: u32) -> Result<u64>;
async fn save_pending_message(&self, message: &Message) -> Result<()>;
async fn get_pending_messages_for_recovery(&self, device_id: &DeviceId)
-> Result<Vec<Message>>;
async fn remove_pending_message(&self, message_id: &uuid::Uuid) -> Result<()>;
async fn get_storage_usage(&self) -> Result<u64>;
async fn cleanup_storage(&self, target_size_bytes: u64) -> Result<u64>;
fn clear_indexes(&self);
fn as_any(&self) -> &dyn std::any::Any;
}
#[async_trait]
pub trait MessageHandler: Send + Sync {
async fn handle_message(&self, message: Message) -> Result<()>;
}
pub trait Plugin: Send + Sync {
fn name(&self) -> &str;
fn version(&self) -> &str;
fn on_load(&self) -> Result<()>;
fn on_unload(&self) -> Result<()>;
}
pub trait ChannelPlugin: Plugin {
fn get_channel(&self) -> std::sync::Arc<dyn Channel>;
}