package com.atlassian.stash.internal.build;

import com.atlassian.bitbucket.build.BuildState;
import com.atlassian.bitbucket.build.BuildSummary;

import java.util.Map;

public class SimpleBuildSummary implements BuildSummary {

    private final Map<BuildState, Integer> statuses;

    public SimpleBuildSummary(Map<BuildState, Integer> statuses) {
        this.statuses = statuses;
    }

    @Override
    public int getSuccessfulCount() {
        return getCount(BuildState.SUCCESSFUL);
    }

    @Override
    public int getFailedCount() {
        return getCount(BuildState.FAILED);
    }

    @Override
    public int getInProgressCount() {
        return getCount(BuildState.INPROGRESS);
    }

    private int getCount(BuildState state) {
        Integer c = statuses.get(state);
        return c == null ? 0 : c;
    }
}
