use crate::error::MinoResult;
use crate::orchestration::podman::ContainerConfig;
use async_trait::async_trait;
use std::collections::HashMap;
use std::path::Path;
#[derive(Debug, Clone)]
pub struct VolumeInfo {
pub name: String,
pub labels: HashMap<String, String>,
pub mountpoint: Option<String>,
pub created_at: Option<String>,
pub size_bytes: Option<u64>,
}
#[async_trait]
pub trait ContainerRuntime: Send + Sync {
async fn is_available(&self) -> MinoResult<bool>;
async fn ensure_ready(&self) -> MinoResult<()>;
async fn run(&self, config: &ContainerConfig, command: &[String]) -> MinoResult<String>;
async fn create(&self, config: &ContainerConfig, command: &[String]) -> MinoResult<String>;
async fn start_attached(&self, container_id: &str) -> MinoResult<i32>;
async fn stop(&self, container_id: &str) -> MinoResult<()>;
async fn kill(&self, container_id: &str) -> MinoResult<()>;
async fn remove(&self, container_id: &str) -> MinoResult<()>;
async fn container_prune(&self) -> MinoResult<()>;
async fn logs(&self, container_id: &str, lines: u32) -> MinoResult<String>;
async fn logs_follow(&self, container_id: &str) -> MinoResult<()>;
async fn image_exists(&self, image: &str) -> MinoResult<bool>;
async fn build_image(&self, context_dir: &Path, tag: &str) -> MinoResult<()>;
async fn build_image_with_progress(
&self,
context_dir: &Path,
tag: &str,
on_output: &(dyn Fn(String) + Send + Sync),
) -> MinoResult<()>;
async fn image_remove(&self, image: &str) -> MinoResult<()>;
async fn image_list_prefixed(&self, prefix: &str) -> MinoResult<Vec<String>>;
fn runtime_name(&self) -> &'static str;
async fn volume_create(&self, name: &str, labels: &HashMap<String, String>) -> MinoResult<()>;
async fn volume_remove(&self, name: &str) -> MinoResult<()>;
async fn volume_list(&self, prefix: &str) -> MinoResult<Vec<VolumeInfo>>;
async fn volume_inspect(&self, name: &str) -> MinoResult<Option<VolumeInfo>>;
async fn volume_disk_usage(&self, prefix: &str) -> MinoResult<HashMap<String, u64>>;
async fn exec_in_container(
&self,
container_id: &str,
command: &[String],
tty: bool,
) -> MinoResult<i32>;
async fn get_container_exit_code(&self, container_id: &str) -> MinoResult<Option<i32>>;
async fn start_detached(&self, container_id: &str) -> MinoResult<()>;
async fn logs_follow_until(
&self,
container_id: &str,
marker: &str,
timeout: std::time::Duration,
on_line: &(dyn Fn(String) + Send + Sync),
) -> MinoResult<bool>;
}