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

import com.atlassian.bitbucket.mesh.io.IoConsumer;

import javax.annotation.Nonnull;
import java.io.OutputStream;
import java.util.List;

public interface HookScriptManager {

    /**
     * Calls the hook scripts identified by {@code ids}.
     *
     * @param ids the IDs of the hook scripts to execute
     * @param parameters parameters for hook script invocation
     * @param callback callback that receives output and execution results from the invoked hook scripts
     */
    void call(@Nonnull List<String> ids, @Nonnull CallHookScriptParameters parameters,
              @Nonnull HookScriptCallback callback);

    /**
     * Retrieves a path where the hook script is stored, or would be stored.
     * <p>
     * Regardless of how the store's implementation manages hook script data, since scripts are, at their core,
     * executables, they must exist somewhere on disk in order to be executed by the OS.
     *
     * @param id the ID of the hook script to retrieve a path for
     * @return the path where the hook script is or would be stored; {@code null} if the ID format is not recognized
     */
    boolean exists(@Nonnull String id);

    /**
     * Saves the hook script in the store
     *
     * @param id the hook script ID
     * @param writer callback that will be called to write to the provided {@link OutputStream}
     */
    void put(@Nonnull String id, @Nonnull IoConsumer<OutputStream> writer);
}
