use super::client::ApiClient;
use super::error::ApiResult;
use super::types::{
ServiceStatus, ServicesStatusResponse, StartServiceRequest, StartServiceResponse,
StopServiceRequest,
};
#[derive(Clone)]
pub struct ServicesApi {
client: ApiClient,
}
impl ServicesApi {
pub fn new(client: ApiClient) -> Self {
Self { client }
}
pub async fn list(&self) -> ApiResult<Vec<ServiceStatus>> {
let response: ServicesStatusResponse = self.client.get("/services").await?;
Ok(response.services)
}
pub async fn start(&self, service: &str, port: Option<u16>) -> ApiResult<StartServiceResponse> {
let request = StartServiceRequest {
service: service.to_string(),
port,
};
self.client.post("/services/start", &request).await
}
pub async fn stop(&self, service: &str) -> ApiResult<StartServiceResponse> {
let request = StopServiceRequest {
service: service.to_string(),
};
self.client.post("/services/stop", &request).await
}
pub async fn is_kubectl_proxy_running(&self) -> ApiResult<bool> {
let services = self.list().await?;
Ok(services.iter().any(|s| s.name == "kubectl-proxy" && s.running))
}
pub async fn start_kubectl_proxy(&self, port: Option<u16>) -> ApiResult<StartServiceResponse> {
self.start("kubectl-proxy", port).await
}
pub async fn stop_kubectl_proxy(&self) -> ApiResult<StartServiceResponse> {
self.stop("kubectl-proxy").await
}
}