use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf};
use crate::error::Result;
use crate::network::NetworkConfig;
use crate::snapshot::SnapshotMetadata;
use crate::volume::VolumeConfig;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StoredImage {
pub reference: String,
pub digest: String,
pub size_bytes: u64,
pub pulled_at: DateTime<Utc>,
pub last_used: DateTime<Utc>,
pub path: PathBuf,
}
pub trait NetworkStoreBackend: Send + Sync {
fn get(&self, name: &str) -> Result<Option<NetworkConfig>>;
fn create(&self, config: NetworkConfig) -> Result<()>;
fn remove(&self, name: &str) -> Result<NetworkConfig>;
fn list(&self) -> Result<Vec<NetworkConfig>>;
fn update(&self, config: &NetworkConfig) -> Result<()>;
}
pub trait VolumeStoreBackend: Send + Sync {
fn get(&self, name: &str) -> Result<Option<VolumeConfig>>;
fn create(&self, config: VolumeConfig) -> Result<VolumeConfig>;
fn remove(&self, name: &str, force: bool) -> Result<VolumeConfig>;
fn list(&self) -> Result<Vec<VolumeConfig>>;
fn update(&self, config: &VolumeConfig) -> Result<()>;
fn prune(&self) -> Result<Vec<String>>;
}
pub trait SnapshotStoreBackend: Send + Sync {
fn save(&self, metadata: SnapshotMetadata, rootfs_source: &Path) -> Result<SnapshotMetadata>;
fn get(&self, id: &str) -> Result<Option<SnapshotMetadata>>;
fn list(&self) -> Result<Vec<SnapshotMetadata>>;
fn delete(&self, id: &str) -> Result<bool>;
fn count(&self) -> Result<usize>;
fn total_size(&self) -> Result<u64>;
fn prune(&self, max_count: usize, max_bytes: u64) -> Result<Vec<String>>;
}
#[async_trait::async_trait]
pub trait ImageStoreBackend: Send + Sync {
async fn get(&self, reference: &str) -> Option<StoredImage>;
async fn get_by_digest(&self, digest: &str) -> Option<StoredImage>;
async fn put(&self, reference: &str, digest: &str, source_dir: &Path) -> Result<StoredImage>;
async fn remove(&self, reference: &str) -> Result<()>;
async fn list(&self) -> Vec<StoredImage>;
async fn evict(&self) -> Result<Vec<String>>;
async fn total_size(&self) -> u64;
}