use crate::driver::{Model, Transport};
use crate::error::ProviderError;
use crate::providers::gemini::cached_content::{
CacheExpiry, CachedContent, CachedContentRequest, CachedContents, NewCachedContent, on_handle,
};
impl<T> Model<CachedContents, T>
where
T: Transport<CachedContents>,
{
pub async fn create(&self, request: NewCachedContent) -> Result<CachedContent, ProviderError> {
self.call(CachedContentRequest::Create(request))
.await?
.resource()
}
pub async fn get(&self, name: &str) -> Result<CachedContent, ProviderError> {
self.call(CachedContentRequest::Get(name.to_owned()))
.await
.map_err(|error| on_handle(error, name))?
.resource()
}
pub async fn list(&self) -> Result<Vec<CachedContent>, ProviderError> {
let pages =
crate::driver::follow_cursors(self.name(), "cached_content", |page_token| async move {
let reply = self.call(CachedContentRequest::List { page_token }).await?;
let next = reply.next_page_token();
Ok((reply.entries()?, next))
})
.await?;
Ok(pages.into_iter().flatten().collect())
}
pub async fn update_expiry(
&self,
name: &str,
expiry: CacheExpiry,
) -> Result<CachedContent, ProviderError> {
let request = CachedContentRequest::UpdateExpiry {
name: name.to_owned(),
expiry,
};
self.call(request)
.await
.map_err(|error| on_handle(error, name))?
.resource()
}
pub async fn delete(&self, name: &str) -> Result<(), ProviderError> {
self.call(CachedContentRequest::Delete(name.to_owned()))
.await
.map_err(|error| on_handle(error, name))?;
Ok(())
}
}