package be.naaturel.boardmateapi.repository.dtos;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

@Document(collection = "games")
public class GameDto {
    @Id
    private String id;
    @Field("players")
    private Map<String, PlayerDto> players;
    @Field("time")
    private TimeControlDto timeControl;
    @Field("moves")
    private List<String> moves;

    public String getId() {
        return id;
    }

    public TimeControlDto getTimeControl() {
        return timeControl;
    }

    public List<String> getMoves() {
        return moves;
    }

    public Map<String, PlayerDto> getPlayers() {
        return players;
    }

    public void setId(String id){
        this.id = id;
    }

    public void setPlayers(Map<String, PlayerDto> players) {
        this.players = players;
    }

    public void setTimeControl(TimeControlDto timeControl) {
        this.timeControl = timeControl;
    }

    public void setMoves(Collection<String> moves) {
        this.moves = new ArrayList<>(moves);
    }

    public void addPlayer(String color, PlayerDto player){
        if(players.size() >= 2) return;
        players.put(color, player);
    }

    public void addMove(String move){
        moves.add(move);
    }

}
