package com.atlassian.bitbucket.mesh.git;

import com.atlassian.util.profiling.Timer;
import com.atlassian.util.profiling.Timers;

import javax.annotation.Nonnull;

import static org.apache.commons.lang3.StringUtils.removeStart;

public class GitTimers {

    public static final String GROUP = "git.";
    public static final Timer CREATE_REPO = Timers.timerWithMetric("git: create repository", GROUP + "CreateRepository");
    public static final Timer DELETE_REPO = Timers.timerWithMetric("git: delete repository", GROUP + "DeleteRepository");
    public static final Timer GC = Timers.timerWithMetric("git: collect garbage", GROUP + "GarbageCollection");
    public static final Timer HOOK = Timers.timer("git: hook");
    public static final Timer MERGE = Timers.timerWithMetric("git: merge", GROUP + "Merge");
    public static final Timer MERGE_TREE = Timers.timerWithMetric("git: merge-tree", GROUP + "MergeTree");
    public static final Timer REBASE = Timers.timerWithMetric("git: rebase", GROUP + "Rebase");
    public static final Timer RESOLVE_EFFECTIVE_DIFF = Timers.timerWithMetric("git: resolve effective diff", GROUP + "ResolveEffectiveDiff");
    public static final Timer REVERT = Timers.timerWithMetric("git: revert", GROUP + "Revert");
    public static final Timer TRANSCODE = Timers.timerWithMetric("git: transcode");

    private GitTimers() {
        throw new IllegalStateException("GitTimers should not be instantiated");
    }

    @Nonnull
    public static Timer hook(String hookName) {
        return Timers.timerWithMetric("git: " + hookName + " hook", GROUP + "hook." + removeStart(hookName, "git-"));
    }
}
