use ek_cfg::Store;
use ek_core::plugin::Plugin;
use std::sync::Arc;
pub fn apply_persisted(
plugin: &dyn Plugin,
store: Option<&Store>,
) -> Result<(), crate::station::StationError> {
let Some(cfg) = plugin.as_configurable() else {
return Ok(()); };
let Some(store) = store else {
return Ok(()); };
let ns = cfg.config_ns();
let outcome = store
.load(ns)
.map_err(|e| crate::station::StationError::Cfg(e.to_string()))?;
let (map, warnings) = match outcome {
ek_cfg::LoadOutcome::Fresh => return Ok(()), ek_cfg::LoadOutcome::Loaded { map, warnings, .. } => (map, warnings),
};
for w in &warnings {
eprintln!("[ek-cfg:{ns}] {w}");
}
let rep = cfg
.apply_config(&map)
.map_err(|e| crate::station::StationError::ApplyRejected { ns: ns.to_owned(), reason: e })?;
if !rep.deferred.is_empty() {
eprintln!(
"[ek-cfg:{ns}] 同步采纳 {},重启插件后生效 {}(BD-CFG-6)",
fmt_keys(&rep.adopted),
fmt_keys(&rep.deferred)
);
}
Ok(())
}
pub fn ns_probe_all(built: &[Arc<dyn Plugin>]) -> Result<(), crate::station::StationError> {
let mut seen = std::collections::BTreeSet::new();
for p in built {
if let Some(cfg) = p.as_configurable() {
let ns = cfg.config_ns();
if !seen.insert(ns.to_owned()) {
return Err(crate::station::StationError::NsDuplicate(ns.to_owned()));
}
}
}
Ok(())
}
fn fmt_keys(keys: &[String]) -> String {
if keys.is_empty() { "(无)".into() } else { keys.join(",") }
}