use std::collections::BTreeMap;
pub mod builtin;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum IntegrationStage {
Experimental,
Beta,
Stable,
Deprecated,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[allow(clippy::struct_excessive_bools)]
pub struct IntegrationCapabilities {
pub oauth: bool,
pub import: bool,
pub export: bool,
pub refresh_tokens: bool,
}
pub trait IntegrationProvider: Send + Sync + 'static {
fn id(&self) -> &'static str;
fn display_name(&self) -> &'static str;
fn stage(&self) -> IntegrationStage;
fn capabilities(&self) -> IntegrationCapabilities;
}
#[derive(Default)]
pub struct IntegrationRegistry {
providers: BTreeMap<&'static str, Box<dyn IntegrationProvider>>,
}
impl IntegrationRegistry {
pub fn new() -> Self {
Self::default()
}
pub fn register<P: IntegrationProvider>(&mut self, provider: P) {
self.providers.insert(provider.id(), Box::new(provider));
}
pub fn has(&self, id: &str) -> bool {
self.providers.contains_key(id)
}
pub fn ids(&self) -> Vec<&'static str> {
self.providers.keys().copied().collect()
}
}
pub fn default_registry() -> IntegrationRegistry {
let mut registry = IntegrationRegistry::new();
builtin::register_all(&mut registry);
registry
}