package com.atlassian.bitbucket.hook.repository;

import com.atlassian.bitbucket.hook.PreReceiveHook;
import com.atlassian.bitbucket.hook.HookResponse;
import com.atlassian.bitbucket.repository.RefChange;

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

/**
 * Configured and enabled Repository Hook that is called just before a push request is completed.
 * <p>
 * This is used in preference over {@link PreReceiveHook} in circumstances where a standard
 * configuration is required. This hook can also be enabled/disabled at the repository level.
 */
public interface PreReceiveRepositoryHook extends RepositoryHookImplementor {

    /**
     * Callback method that is called just before a push request is completed. This hook executes during the processing
     * of a push and the client will have to wait during the execution of the {@code onReceive} method.
     *
     * @param context      the context which the hook is being run with
     * @param refChanges   the refs that are about to be updated
     * @param hookResponse used to write to the client's stdout and/or stderr
     * @return {@code true} if the push request is to be accepted, {@code false} if it should be rejected.
     *         <em>Note</em> that returning {@code true} does not guarantee that the push will be accepted as there may
     *         be other {@link PreReceiveHook}s that reject the push.
     */
    boolean onReceive(@Nonnull RepositoryHookContext context, @Nonnull Collection<RefChange> refChanges, @Nonnull HookResponse hookResponse);
}
