package objects;

import java.util.ArrayList;

import com.google.common.collect.Lists;

public class OverUnder {

    private Float key;
    private final ArrayList<Integer> goals;
    private int total;
    private int draws;
    private int totalGames;

    public OverUnder() {
        goals = Lists.newArrayList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    }

    public OverUnder(Float key) {
        this.key = key;
        goals = Lists.newArrayList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    }

    public void addGoalStat(int numGoals) {
        if (numGoals > 9) {
            Integer val = goals.get(9);
            val++;
            goals.set(9, val);
        } else {
            Integer val = goals.get(numGoals);
            val++;
            goals.set(numGoals, val);
        }

        updateTotal();
    }

    private void updateTotal() {
        total = 0;
        goals.forEach(g -> total += g);
    }

    public Float getKey() {
        return key;
    }

    public void setKey(Float key) {
        this.key = key;
    }

    public ArrayList<Integer> getGoals() {
        return goals;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public float calcMinOdds(int numGoals) {
        if (numGoals == 0) {
            return 1F;
        }
        return 1 / (1 / (goals.stream().mapToInt(Integer::intValue).sum() / Float.valueOf(numGoals)));

    }

    public int getDraws() {
        return draws;
    }

    public void setDraws(int draws) {
        this.draws = draws;
    }

    public int getTotalGames() {
        return totalGames;
    }

    public void setTotalGames(int totalGames) {
        this.totalGames = totalGames;
    }
}
