use serde_json::{json, Value};
use crate::proxy::DaemonClient;
fn to_string(v: Value) -> Result<String, String> {
serde_json::to_string(&v).map_err(|e| e.to_string())
}
pub async fn create(
client: &DaemonClient,
name: &str,
kind: Option<&str>,
) -> Result<String, String> {
let mut params = json!({ "name": name });
if let Some(kind) = kind {
params["kind"] = json!(kind);
}
client
.call("coder.projects.create", params)
.await
.and_then(to_string)
}
pub async fn list(client: &DaemonClient) -> Result<String, String> {
client
.call("coder.projects.list", json!({}))
.await
.and_then(to_string)
}
pub async fn get(client: &DaemonClient, slug: &str) -> Result<String, String> {
client
.call("coder.projects.get", json!({ "slug": slug }))
.await
.and_then(to_string)
}