#![doc = include_str!("../../../docs/league/season/week.md")]
#[cfg(feature = "rocket_okapi")]
use rocket_okapi::okapi::schemars;
#[cfg(feature = "rocket_okapi")]
use rocket_okapi::okapi::schemars::JsonSchema;
use serde::{Serialize, Deserialize};
use crate::league::season::matchup::LeagueSeasonMatchup;
#[cfg_attr(feature = "rocket_okapi", derive(JsonSchema))]
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify))]
#[cfg_attr(feature = "wasm", tsify(into_wasm_abi, from_wasm_abi))]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Serialize, Deserialize)]
pub struct LeagueSeasonWeek {
matchups: Vec<LeagueSeasonMatchup>
}
impl Default for LeagueSeasonWeek {
fn default() -> Self {
LeagueSeasonWeek {
matchups: Vec::new()
}
}
}
impl LeagueSeasonWeek {
pub fn new() -> LeagueSeasonWeek {
LeagueSeasonWeek::default()
}
pub fn matchups(&self) -> &Vec<LeagueSeasonMatchup> {
&self.matchups
}
pub fn matchups_mut(&mut self) -> &mut Vec<LeagueSeasonMatchup> {
&mut self.matchups
}
pub fn started(&self) -> bool {
if self.matchups.is_empty() {
return false;
}
for matchup in self.matchups.iter() {
if matchup.context().game_over() {
return true;
}
}
false
}
pub fn complete(&self) -> bool {
if self.matchups.is_empty() {
return false;
}
for matchup in self.matchups.iter() {
if !matchup.context().game_over() {
return false;
}
}
true
}
pub fn team_matchup(&self, id: usize) -> Option<LeagueSeasonMatchup> {
for matchup in self.matchups.iter() {
if matchup.participated(id) {
return Some(matchup.clone());
}
}
None
}
}