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

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * Represents a SCM hook request. Hooks call back into the application providing:
 * <ul>
 *     <li>the hook identifier (e.g. git-pre-receive)</li>
 *     <li>the environment variables set by the SCM</li>
 *     <li>any arguments provided to the hook</li>
 *     <li>any remaining input</li>
 * </ul>
 */
public interface HookRequest {

    /**
     * @return the {@code git} command that triggered the hook; {@code null} if not available
     */
    @Nullable
    String getCommand();

    /**
     * @return the list of arguments provided by the SCM hook callback
     */
    @Nonnull
    List<String> getArguments();

    /**
     * @return the environment variables set by the SCM when the hook was run
     */
    @Nonnull
    default Map<String, String> getEnvironment() {
        return Collections.emptyMap();
    }

    /**
     * @return the hook-identifier provided by the SCM hook callback
     */
    @Nullable
    String getHookName();

    /**
     * Retrieves the {@link HookStdin stdin} that was provided to the hook. This may be called multiple times, or the
     * returned {@link HookStdin} may be {@link HookStdin#open opened} multiple times, and will receive the same data
     * each time <i>unless</i> {@code stdin} has been {@link HookStdin#release released}.
     *
     * @return {@code stdin} data
     */
    @Nonnull
    HookStdin getStdin();
}
