use crate::metadata::{
Constraints, OptionEntry, ParamCondition, ParamConditionEntry, ParameterDef, ParameterType,
};
pub(super) fn param(
name: &str,
label: &str,
description: &str,
param_type: ParameterType,
) -> ParameterDef {
ParameterDef {
name: name.to_string(),
label: label.to_string(),
description: description.to_string(),
param_type,
..Default::default()
}
}
pub(super) fn enum_of(options: &[(&str, &str)]) -> ParameterType {
ParameterType::Enum {
options: options
.iter()
.map(|(value, label)| OptionEntry {
value: (*value).to_string(),
label: (*label).to_string(),
})
.collect(),
}
}
pub(super) fn visible_when(param: &str, equals: &str) -> ParamCondition {
ParamCondition::Single(entry(param, equals))
}
pub(super) fn visible_when_any(conditions: &[(&str, &str)]) -> ParamCondition {
ParamCondition::Any(conditions.iter().map(|(p, e)| entry(p, e)).collect())
}
fn entry(param: &str, equals: &str) -> ParamConditionEntry {
ParamConditionEntry {
param: param.to_string(),
equals: equals.to_string(),
}
}
pub(super) fn required(required: bool) -> Constraints {
Constraints {
min: None,
max: None,
required,
}
}
pub(super) fn min(min: f64, required: bool) -> Constraints {
Constraints {
min: Some(min),
max: None,
required,
}
}