//! Directive API methods.
use serde::Serialize;
use uuid::Uuid;
use super::client::{ApiClient, ApiError};
use super::supervisor::JsonValue;
/// Request to update a directive.
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UpdateDirectiveRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<i32>,
}
impl ApiClient {
/// Get directive status and details.
pub async fn directive_status(&self, directive_id: Uuid) -> Result<JsonValue, ApiError> {
self.get(&format!("/api/v1/directives/{}", directive_id))
.await
}
/// List chains for a directive.
pub async fn directive_chains(&self, directive_id: Uuid) -> Result<JsonValue, ApiError> {
self.get(&format!("/api/v1/directives/{}/chains", directive_id))
.await
}
/// Get a chain with its steps.
pub async fn directive_chain(
&self,
directive_id: Uuid,
chain_id: Uuid,
) -> Result<JsonValue, ApiError> {
self.get(&format!(
"/api/v1/directives/{}/chains/{}",
directive_id, chain_id
))
.await
}
/// Update a directive.
pub async fn directive_update(
&self,
directive_id: Uuid,
req: UpdateDirectiveRequest,
) -> Result<JsonValue, ApiError> {
self.put(&format!("/api/v1/directives/{}", directive_id), &req)
.await
}
/// Start a directive (transition from draft to planning).
pub async fn directive_start(&self, directive_id: Uuid) -> Result<JsonValue, ApiError> {
self.post_empty(&format!("/api/v1/directives/{}/start", directive_id))
.await
}
/// Trigger a manual evaluation for a step.
pub async fn directive_evaluate_step(
&self,
directive_id: Uuid,
step_id: Uuid,
) -> Result<JsonValue, ApiError> {
self.post_empty(&format!(
"/api/v1/directives/{}/steps/{}/evaluate",
directive_id, step_id
))
.await
}
/// Submit a chain plan for a directive.
pub async fn directive_submit_plan(
&self,
directive_id: Uuid,
plan_json: &str,
) -> Result<JsonValue, ApiError> {
#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
struct SubmitPlanBody {
plan: String,
}
self.post(
&format!("/api/v1/directives/{}/submit-plan", directive_id),
&SubmitPlanBody {
plan: plan_json.to_string(),
},
)
.await
}
/// List evaluations for a step.
pub async fn directive_evaluations(
&self,
directive_id: Uuid,
step_id: Uuid,
) -> Result<JsonValue, ApiError> {
self.get(&format!(
"/api/v1/directives/{}/steps/{}/evaluations",
directive_id, step_id
))
.await
}
}