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

import com.atlassian.bitbucket.mesh.process.ProcessSummary;

import javax.annotation.Nonnull;
import java.nio.ByteBuffer;

public interface HookScriptCallback {

    /**
     * @return {@code true} when the caller wants to cancel further script invocations
     */
    boolean isCanceled();

    /**
     * Called when the underlying process completes.
     *
     * @param summary a summary of the completed process
     */
    void onComplete(@Nonnull ProcessSummary summary);

    /**
     * Called just before the hook script with ID {@code hookScriptId} is started.
     *
     * @param hookScriptId the ID of the hook script
     */
    void onStartScript(@Nonnull String hookScriptId);

    /**
     * Called when the executing hook script wrote to stderr.
     *
     * @param buffer a buffer containing {@code stderr} bytes
     * @param closed {@code true} to indicate the process has closed its {@code stderr} pipe; otherwise,
     *               {@code false} to indicate the pipe is still open
     */
    void onStderr(@Nonnull ByteBuffer buffer, boolean closed);

    /**
     * Called when the executing hook script wrote to stdout.
     *
     * @param buffer a buffer containing {@code stdout} bytes
     * @param closed {@code true} to indicate the process has closed its {@code stdout} pipe; otherwise,
     *               {@code false} to indicate the pipe is still open
     */
    void onStdout(@Nonnull ByteBuffer buffer, boolean closed);
}
