#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum Piece {
    WK,
    WQ,
    WR,
    WB,
    WN,
    WP,
    BK,
    BQ,
    BR,
    BB,
    BN,
    BP,
    NO,
}

pub fn piece_for_colour(piece: &Piece, white_to_move: bool) -> Piece {
    if white_to_move {
        match piece {
            Piece::BK => Piece::WK,
            Piece::BQ => Piece::WQ,
            Piece::BB => Piece::WB,
            Piece::BN => Piece::WN,
            Piece::BR => Piece::WR,
            Piece::BP => Piece::WP,
            _ => piece.clone(),
        }
    } else {
        match piece {
            Piece::WK => Piece::BK,
            Piece::WQ => Piece::BQ,
            Piece::WB => Piece::BB,
            Piece::WN => Piece::BN,
            Piece::WR => Piece::BR,
            Piece::WP => Piece::BP,
            _ => piece.clone(),
        }
    }
}

pub fn piece_from(name: &str) -> Piece {
    match name {
        "K" => Piece::WK,
        "Q" => Piece::WQ,
        "B" => Piece::WB,
        "N" => Piece::WN,
        "R" => Piece::WR,
        "P" => Piece::WP,
        "k" => Piece::BK,
        "q" => Piece::BQ,
        "b" => Piece::BB,
        "n" => Piece::BN,
        "r" => Piece::BR,
        "p" => Piece::BP,
        _ => Piece::NO,
    }
}

pub fn piece_to_string(piece: &Piece) -> String {
    String::from(match piece {
        Piece::WK => "K",
        Piece::WQ => "Q",
        Piece::WB => "B",
        Piece::WN => "N",
        Piece::WR => "R",
        Piece::WP => "P",
        Piece::BK => "k",
        Piece::BQ => "q",
        Piece::BB => "b",
        Piece::BN => "n",
        Piece::BR => "r",
        Piece::BP => "p",
        Piece::NO => "-",
    })
}
