use serde::Serialize;
use crate::CommandClient;
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ChartRegion {
pub x_min: f64,
pub x_max: f64,
#[serde(skip_serializing_if = "Option::is_none")]
pub label: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub color: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub border_color: Option<String>,
}
impl ChartRegion {
pub fn new(x_min: f64, x_max: f64) -> Self {
Self { x_min, x_max, label: None, color: None, border_color: None }
}
pub fn with_label(mut self, label: impl Into<String>) -> Self {
self.label = Some(label.into());
self
}
pub fn with_color(mut self, color: impl Into<String>) -> Self {
self.color = Some(color.into());
self
}
pub fn with_border_color(mut self, color: impl Into<String>) -> Self {
self.border_color = Some(color.into());
self
}
}
pub fn set_chart_regions(
client: &mut CommandClient,
project_id: &str,
method_id: &str,
run_id: Option<&str>,
name: &str,
cycle_index: u32,
regions: &[ChartRegion],
) -> u32 {
let mut payload = serde_json::json!({
"project_id": project_id,
"method_id": method_id,
"name": name,
"cycle_index": cycle_index,
"regions": regions,
});
if let (Some(rid), Some(obj)) = (run_id, payload.as_object_mut()) {
obj.insert("run_id".to_string(), serde_json::json!(rid));
}
client.send("tis.set_chart_regions", payload)
}