use super::InfiniteClientError;
use super::client::HaloInfiniteClient;
use super::models::{MatchHistoryEntry, MatchHistoryType};
use super::player::Player;
pub const MAX_PAGE_SIZE: u32 = 25;
pub struct MatchHistoryPager {
client: HaloInfiniteClient,
player: Player,
match_type: MatchHistoryType,
start: u32,
done: bool,
}
impl MatchHistoryPager {
pub(crate) fn new(
client: HaloInfiniteClient,
player: Player,
match_type: MatchHistoryType,
) -> Self {
Self {
client,
player,
match_type,
start: 0,
done: false,
}
}
pub async fn next_page(&mut self) -> Result<Vec<MatchHistoryEntry>, InfiniteClientError> {
if self.done {
return Ok(Vec::new());
}
let page = self
.client
.player_matches_of_type(&self.player, self.start, MAX_PAGE_SIZE, self.match_type)
.await?;
let len = page.results.len() as u32;
self.start += len;
if len < MAX_PAGE_SIZE {
self.done = true;
}
Ok(page.results)
}
pub fn is_done(&self) -> bool {
self.done
}
}