use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
#[serde(default, deny_unknown_fields)]
pub struct PluginsConfig {
pub plugins: BTreeMap<String, PluginConfig>,
}
impl PluginsConfig {
pub fn merge_from(&mut self, other: Self) {
for (id, patch) in other.plugins {
self.plugins
.entry(id)
.and_modify(|existing| existing.merge_from(patch.clone()))
.or_insert(patch);
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
#[serde(default, deny_unknown_fields)]
pub struct PluginConfig {
pub enabled: Option<bool>,
pub config: Option<serde_json::Value>,
}
impl PluginConfig {
pub fn merge_from(&mut self, other: Self) {
if other.enabled.is_some() {
self.enabled = other.enabled;
}
if other.config.is_some() {
self.config = other.config;
}
}
}