use async_trait::async_trait;
use thiserror::Error;
use kaish_kernel::ast::Value;
use kaish_kernel::interpreter::ExecResult;
pub type ClientResult<T> = Result<T, ClientError>;
#[derive(Debug, Error)]
pub enum ClientError {
#[error("connection error: {0}")]
Connection(String),
#[error("execution error: {0}")]
Execution(String),
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("utf8 error: {0}")]
Utf8(#[from] std::str::Utf8Error),
#[error("not connected")]
NotConnected,
#[error("{0}")]
Other(#[from] anyhow::Error),
}
#[async_trait(?Send)]
pub trait KernelClient {
async fn execute(&self, input: &str) -> ClientResult<ExecResult>;
async fn get_var(&self, name: &str) -> ClientResult<Option<Value>>;
async fn set_var(&self, name: &str, value: Value) -> ClientResult<()>;
async fn list_vars(&self) -> ClientResult<Vec<(String, Value)>>;
async fn cwd(&self) -> ClientResult<String>;
async fn set_cwd(&self, path: &str) -> ClientResult<()>;
async fn last_result(&self) -> ClientResult<ExecResult>;
async fn reset(&self) -> ClientResult<()>;
async fn ping(&self) -> ClientResult<String>;
async fn shutdown(&self) -> ClientResult<()>;
async fn read_blob(&self, id: &str) -> ClientResult<Vec<u8>>;
async fn write_blob(&self, content_type: &str, data: &[u8]) -> ClientResult<String>;
async fn delete_blob(&self, id: &str) -> ClientResult<bool>;
}