use snafu::ResultExt;
use std::sync::Arc;
use super::model::*;
use super::*;
use crate::client::GeminiClient;
pub struct CachedContentHandle {
pub name: String,
client: Arc<GeminiClient>,
}
impl CachedContentHandle {
pub(crate) fn new(name: String, client: Arc<GeminiClient>) -> Self {
Self { name, client }
}
pub fn name(&self) -> &str {
&self.name
}
pub async fn get(&self) -> Result<CachedContent, Error> {
self.client.get_cached_content(&self.name).await.map_err(Box::new).context(ClientSnafu)
}
pub async fn update(&self, expiration: CacheExpirationRequest) -> Result<CachedContent, Error> {
self.client
.update_cached_content(&self.name, expiration)
.await
.map_err(Box::new)
.context(ClientSnafu)
}
pub async fn delete(self) -> Result<(), (Self, Error)> {
match self
.client
.delete_cached_content(&self.name)
.await
.map_err(Box::new)
.context(ClientSnafu)
{
Ok(response) => Ok(response),
Err(e) => Err((self, e)),
}
}
}