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;

/// Parameters for [`VersusInfo::get`]
#[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 {
	/// GET versus info between two players using `params`
	pub async fn get<'a>(
		user_1: &UserIdentifier<'a>,
		user_2: &UserIdentifier<'a>,
		params: impl Into<Option<&'a GetVersusInfoParams>>,
	) -> Result<Self> {
		make_request!(
			"https://api.mcsrranked.com/users/{}/versus/{}"
			[user_1, user_2]
			params.into()
		)
	}
	#[cfg(feature = "matches")]
	/// GET versus matches between two players using `params`
	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!(
			"https://api.mcsrranked.com/users/{}/versus/{}"
			[user_1, user_2]
			params.into()
		)
	}
}

#[cfg(feature = "blocking")]
impl VersusInfo {
	/// Synchronously GET versus info between two players using `params`
	pub fn get_blocking<'a>(
		user_1: &UserIdentifier<'a>,
		user_2: &UserIdentifier<'a>,
		params: impl Into<Option<&'a GetVersusInfoParams>>,
	) -> Result<Self> {
		make_request_blocking!(
			"https://api.mcsrranked.com/users/{}/versus/{}"
			[user_1, user_2]
			params.into()
		)
	}
	#[cfg(feature = "matches")]
	/// Synchronounsly GET versus matches between two players using `params`
	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!(
			"https://api.mcsrranked.com/users/{}/versus/{}"
			[user_1, user_2]
			params.into()
		)
	}
}
