use serde::{Deserialize, Serialize};
use zeroize::Zeroizing;
use crate::error::Result;
use crate::identity::{IdentityStore, SessionIdentity};
pub mod wire;
#[cfg(feature = "engine")]
pub mod live;
#[cfg(feature = "engine")]
pub mod attached;
#[cfg(all(feature = "engine", feature = "tier-matrix"))]
pub mod sliding;
#[cfg(feature = "tier-server")]
pub mod server;
#[cfg(feature = "tier-matrix")]
pub mod matrix;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum BackendKind {
Server,
Matrix,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Capabilities {
pub rooms: bool,
pub federation: bool,
}
pub struct Session {
pub token: Zeroizing<String>,
pub nick: String,
pub cred_ref: String,
pub user_id: Option<String>,
pub device_id: Option<String>,
}
impl std::fmt::Debug for Session {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Session").field("nick", &self.nick).field("cred_ref", &self.cred_ref).field("user_id", &self.user_id).field("device_id", &self.device_id).field("token", &"<hidden>").finish()
}
}
pub trait Backend: Send + Sync {
fn kind(&self) -> BackendKind;
fn capabilities(&self) -> Capabilities;
fn server_ref(&self) -> &str;
fn ensure_session(&self, ids: &IdentityStore, id: &mut SessionIdentity, invite: Option<&str>) -> Result<Session>;
#[cfg(feature = "engine")]
fn execute(&self, request: &mail4agent_messenger::OutgoingRequest) -> Result<mail4agent_messenger::HttpResponseDescriptor>;
#[cfg(feature = "engine")]
fn frozen(&self) -> Option<std::sync::Arc<dyn Backend>> {
None
}
#[cfg(feature = "engine")]
fn whoami(&self) -> Result<(String, String)>;
#[cfg(feature = "engine")]
fn keep_prefix(&self) -> bool;
#[cfg(feature = "engine")]
fn wait_for_news(&self, timeout: std::time::Duration) -> Result<crate::engine::News>;
}