use serde::{Deserialize, Deserializer, Serialize};
#[cfg_attr(feature = "export", derive(tsify::Tsify))]
#[cfg_attr(
feature = "export",
tsify(into_wasm_abi, from_wasm_abi, type_suffix = "V1")
)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MultiplayerScore {
pub slot: String, pub team: String, pub user_id: String, pub score: String, pub maxcombo: String, pub rank: String, pub count50: String, pub count100: String, pub count300: String, pub countmiss: String, pub countgeki: String, pub countkatu: String, pub perfect: String, pub pass: String, pub enabled_mods: Option<String>, }
#[cfg_attr(feature = "export", derive(tsify::Tsify))]
#[cfg_attr(feature = "export", tsify(into_wasm_abi, from_wasm_abi))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MultiplayerGame {
pub game_id: String, pub start_time: String, pub end_time: String, pub beatmap_id: String, pub play_mode: String, pub match_type: String, pub scoring_type: String, pub team_type: String, pub mods: String, pub scores: Vec<MultiplayerScore>, }
#[cfg_attr(feature = "export", derive(tsify::Tsify))]
#[cfg_attr(feature = "export", tsify(into_wasm_abi, from_wasm_abi))]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct MultiplayerMatch {
pub match_id: String, pub name: String, pub start_time: String, pub end_time: Option<String>, }
#[cfg_attr(feature = "export", derive(tsify::Tsify))]
#[cfg_attr(feature = "export", tsify(into_wasm_abi, from_wasm_abi))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MultiplayerResponse {
#[serde(rename = "match", deserialize_with = "deserialize_match")]
pub matchh: MultiplayerMatch, pub games: Vec<MultiplayerGame>, }
fn deserialize_match<'de, D>(deserializer: D) -> Result<MultiplayerMatch, D::Error>
where
D: Deserializer<'de>,
{
#[derive(Deserialize)]
#[serde(untagged)]
#[allow(dead_code)]
enum MatchField {
Object(MultiplayerMatch),
Number(i64),
Bool(bool),
Null,
}
let value = MatchField::deserialize(deserializer)?;
match value {
MatchField::Object(obj) => Ok(obj),
MatchField::Number(_) | MatchField::Bool(_) | MatchField::Null => {
Ok(MultiplayerMatch::default())
}
}
}
#[cfg_attr(feature = "export", derive(tsify::Tsify))]
#[cfg_attr(feature = "export", tsify(into_wasm_abi, from_wasm_abi))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct GetMatchParamsRaw {
pub k: Option<String>, pub mp: Option<String>, }
#[cfg_attr(feature = "export", derive(tsify::Tsify))]
#[cfg_attr(feature = "export", tsify(into_wasm_abi, from_wasm_abi))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct GetMatchParams {
pub api_key: Option<String>, pub match_id: Option<String>, }
impl GetMatchParams {
pub fn api_key(mut self, api_key: String) -> Self {
self.api_key = Some(api_key);
self
}
pub fn match_id(mut self, match_id: String) -> Self {
self.match_id = Some(match_id);
self
}
pub fn build_params(&self) -> Vec<(String, String)> {
let mut params = Vec::new();
if let Some(ref api_key) = self.api_key {
params.push(("k".to_string(), api_key.clone()));
}
if let Some(ref match_id) = self.match_id {
params.push(("mp".to_string(), match_id.clone()));
}
params
}
pub fn to_raw(&self) -> GetMatchParamsRaw {
GetMatchParamsRaw {
k: self.api_key.clone(),
mp: self.match_id.clone(),
}
}
}
impl GetMatchParamsRaw {
pub fn k(mut self, api_key: String) -> Self {
self.k = Some(api_key);
self
}
pub fn mp(mut self, match_id: String) -> Self {
self.mp = Some(match_id);
self
}
pub fn build_params(&self) -> Vec<(String, String)> {
let mut params = Vec::new();
if let Some(ref api_key) = self.k {
params.push(("k".to_string(), api_key.clone()));
}
if let Some(ref match_id) = self.mp {
params.push(("mp".to_string(), match_id.clone()));
}
params
}
}