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

import com.atlassian.bitbucket.mesh.repository.Repository;

import javax.annotation.Nonnull;

/**
 * A Git hook callback.
 * <p>
 * Each handler has a name that must match git hook name.
 */
public interface GitHookHandler {

    /**
     * Used to match handler for incoming git hook request
     *
     * @return hook name
     */
    @Nonnull
    String getHookName();

    /**
     * @param repository   a repository for which the hook is running
     * @param request      hook request
     * @param outputWriter a write for handler to write git output into.
     * @return true if the handler accepted the request, false otherwise
     */
    boolean handle(@Nonnull Repository repository, @Nonnull HookRequest request,
                   @Nonnull GitHookOutputWriter outputWriter);

    default void onHookContextClose() {
    }
}
