use serde_json::Value;
use crate::Result;
use crate::bindings::oino::extension::registry as wr;
use crate::error::parse;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Scope {
Global,
Project,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum Layer {
#[default]
Effective,
Global,
Project,
}
pub fn get(namespace: &str, layer: Layer) -> Result<Value> {
let layer = match layer {
Layer::Effective => wr::SettingsLayer::Effective,
Layer::Global => wr::SettingsLayer::Global,
Layer::Project => wr::SettingsLayer::Project,
};
parse(&wr::extension_settings(namespace, layer)?)
}
pub fn set(namespace: &str, key: &str, value: Option<&Value>, scope: Scope) -> Result<()> {
let scope = match scope {
Scope::Global => wr::SettingsScope::Global,
Scope::Project => wr::SettingsScope::Project,
};
let value = value.map(Value::to_string);
Ok(wr::set_extension_setting(
namespace,
key,
value.as_deref(),
scope,
)?)
}