package com.atlassian.bitbucket.mesh.git.gc;

import javax.annotation.Nonnull;
import java.util.*;

class GcContext {

    private final List<GcAction> actions;
    private final Set<GcActionType> successTypes;

    GcContext() {
        actions = new ArrayList<>();
        successTypes = EnumSet.noneOf(GcActionType.class);
    }

    void addAction(GcAction action) {
        if (!action.isFailed()) {
            successTypes.add(action.getAction());
        }
        actions.add(action);
    }

    void addAction(GcActionType action, long startMs) {
        addAction(action, startMs, null);
    }

    void addAction(GcActionType action, long startMs, String detail) {
        addAction(action, startMs, detail, false);
    }

    void addAction(GcActionType action, long startMs, String detail, boolean failed) {
        addAction(new GcAction(action, startMs, detail, failed));
    }

    @Nonnull
    List<GcAction> getActions() {
        return Collections.unmodifiableList(actions);
    }

    boolean isSuccess(GcActionType action) {
        return successTypes.contains(action);
    }
}
