use crate::client::Client;
use crate::error::Error;
use crate::types::{Id, MatchDetailsResponse, ProfileResponse};
pub struct Player<'a> {
id: Id,
client: &'a Client,
}
impl<'a> Player<'a> {
pub fn new(id: impl Into<Id>, client: &'a Client) -> Self {
Self {
id: id.into(),
client,
}
}
pub fn id(&self) -> &Id {
&self.id
}
pub async fn profile(&self) -> Result<ProfileResponse, Error> {
self.client.get_profile(self.id.clone()).await
}
pub async fn matches(&self) -> Result<Vec<MatchDetailsResponse>, Error> {
self.client.get_profile_matches(self.id.clone()).await
}
}
#[cfg(feature = "player")]
impl Client {
pub fn player(&self, id: impl Into<Id>) -> crate::player::Player<'_> {
crate::player::Player::new(id, self)
}
}