use serde::{Deserialize, Serialize};
use sgf::{
    go::{Game, Rank},
    Date,
};
use typeshare::typeshare;

#[derive(Clone, Debug, Deserialize, Serialize)]
#[typeshare]
pub struct GamePreviewElement {
    pub date: Vec<Date>,
    pub black_player: String,
    pub black_rank: Option<Rank>,
    pub white_player: String,
    pub white_rank: Option<Rank>,
}

impl GamePreviewElement {
    pub fn new(game: &Game) -> GamePreviewElement {
        GamePreviewElement {
            date: game.info.date.clone(),
            black_player: game
                .info
                .black_player
                .clone()
                .unwrap_or("black_player".to_owned()),
            black_rank: game.info.black_rank.clone(),
            white_player: game
                .info
                .white_player
                .clone()
                .unwrap_or("white_player".to_owned()),
            white_rank: game.info.white_rank.clone(),
        }
    }
}
