use super::{Lookup, Model};
use crate::reply::balls::BallRow;
use crate::ui::Channel;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Columns {
pub channel: Channel,
pub board: crate::reply::board::Board,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Bindings {
pub channel: Channel,
pub rows: Vec<BallRow>,
}
impl Model {
pub fn begin_board(&mut self) {
self.lookup = Some(Lookup::Board);
}
pub fn boarding(&self) -> bool {
self.lookup == Some(Lookup::Board)
}
pub(super) fn columned(&mut self, channel: &Channel, board: crate::reply::board::Board) {
let answered = Columns {
channel: channel.clone(),
board,
};
match self
.columns
.iter_mut()
.find(|held| held.channel.name == channel.name)
{
Some(held) => *held = answered,
None => self.columns.push(answered),
}
}
pub(super) fn bound(&mut self, channel: &Channel, rows: Vec<BallRow>) {
let answered = Bindings {
channel: channel.clone(),
rows,
};
match self
.bindings
.iter_mut()
.find(|held| held.channel.name == channel.name)
{
Some(held) => *held = answered,
None => self.bindings.push(answered),
}
}
pub(super) fn retire_wall_balls(&mut self) {
self.holding = None;
self.marks = None;
}
}
#[cfg(test)]
mod tests;