use std::path::{Path, PathBuf};
use async_trait::async_trait;
use kaish_types::backend::{
BackendResult, MountInfo, PatchOp, ReadRange, ToolInfo, ToolResult, WriteMode,
};
use kaish_types::{DirEntry, ToolArgs};
use crate::ctx::ToolCtx;
#[async_trait]
pub trait KernelBackend: Send + Sync {
async fn read(&self, path: &Path, range: Option<ReadRange>) -> BackendResult<Vec<u8>>;
async fn write(&self, path: &Path, content: &[u8], mode: WriteMode) -> BackendResult<()>;
async fn append(&self, path: &Path, content: &[u8]) -> BackendResult<()>;
async fn patch(&self, path: &Path, ops: &[PatchOp]) -> BackendResult<()>;
async fn list(&self, path: &Path) -> BackendResult<Vec<DirEntry>>;
async fn stat(&self, path: &Path) -> BackendResult<DirEntry>;
async fn mkdir(&self, path: &Path) -> BackendResult<()>;
async fn set_mtime(&self, path: &Path, mtime: std::time::SystemTime) -> BackendResult<()>;
async fn remove(&self, path: &Path, recursive: bool) -> BackendResult<()>;
async fn rename(&self, from: &Path, to: &Path) -> BackendResult<()>;
async fn exists(&self, path: &Path) -> bool;
async fn lstat(&self, path: &Path) -> BackendResult<DirEntry>;
async fn read_link(&self, path: &Path) -> BackendResult<PathBuf>;
async fn symlink(&self, target: &Path, link: &Path) -> BackendResult<()>;
async fn call_tool(
&self,
name: &str,
args: ToolArgs,
ctx: &mut dyn ToolCtx,
) -> BackendResult<ToolResult>;
async fn list_tools(&self) -> BackendResult<Vec<ToolInfo>>;
async fn get_tool(&self, name: &str) -> BackendResult<Option<ToolInfo>>;
fn read_only(&self) -> bool;
fn backend_type(&self) -> &str;
fn mounts(&self) -> Vec<MountInfo>;
fn resolve_real_path(&self, path: &Path) -> Option<PathBuf>;
}