use serde::Serialize;
#[cfg(feature = "matches")]
use crate::game::{MatchInfo, requests::GetMatchesParams};
#[cfg(feature = "blocking")]
use crate::helpers::make_request_blocking;
use crate::{Result, helpers::make_request, types::Season, user::identifier::UserIdentifier};
use super::VersusInfo;
const BASE_URL: &str = "https://api.mcsrranked.com/users/{}/versus/{}";
const MATCHES_URL: &str = "https://api.mcsrranked.com/users/{}/versus/{}";
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetVersusInfoParams {
pub season: Option<Season>,
}
impl GetVersusInfoParams {
pub fn season(season: Season) -> Self {
Self {
season: Some(season),
}
}
}
impl VersusInfo {
pub async fn get<'a>(
user_1: &UserIdentifier<'a>,
user_2: &UserIdentifier<'a>,
params: impl Into<Option<&'a GetVersusInfoParams>>,
) -> Result<Self> {
make_request(
BASE_URL,
[&user_1.to_string(), &user_2.to_string()],
params.into(),
)
.await
}
#[cfg(feature = "matches")]
pub async fn get_matches<'a>(
user_1: &UserIdentifier<'a>,
user_2: &UserIdentifier<'a>,
params: impl Into<Option<&'a GetMatchesParams>>,
) -> Result<Vec<MatchInfo>> {
make_request(
MATCHES_URL,
[&user_1.to_string(), &user_2.to_string()],
params.into(),
)
.await
}
}
#[cfg(feature = "blocking")]
impl VersusInfo {
pub fn get_blocking<'a>(
user_1: &UserIdentifier<'a>,
user_2: &UserIdentifier<'a>,
params: impl Into<Option<&'a GetVersusInfoParams>>,
) -> Result<Self> {
make_request_blocking(
BASE_URL,
[&user_1.to_string(), &user_2.to_string()],
params.into(),
)
}
#[cfg(feature = "matches")]
pub fn get_matches_blocking<'a>(
user_1: &UserIdentifier<'a>,
user_2: &UserIdentifier<'a>,
params: impl Into<Option<&'a GetMatchesParams>>,
) -> Result<Vec<MatchInfo>> {
make_request_blocking(
MATCHES_URL,
[&user_1.to_string(), &user_2.to_string()],
params.into(),
)
}
}