use std::rc::Rc;
use std::sync::RwLock;
use crate::api::exec_request;
use crate::model::Show;
use crate::model::id::ShowId;
use crate::{Cache, CachePolicy, Config};
use super::{Error, make_request};
pub struct Client {
config: Rc<Config>,
cache: Rc<dyn Cache>,
policy: Rc<RwLock<CachePolicy>>,
}
impl Client {
pub fn new(config: Rc<Config>, cache: Rc<dyn Cache>, policy: Rc<RwLock<CachePolicy>>) -> Self {
Self {
config,
cache,
policy,
}
}
}
impl Client {
pub async fn get_details(
&self,
id: impl Into<ShowId>,
language: Option<&str>,
) -> Result<Show, Error> {
let request = make_request(
&self.config,
&format!("/3/tv/{}", id.into().into_raw()),
language,
)?;
exec_request(&self.config, &*self.cache, &self.policy, request).await
}
}