package com.atlassian.stash.internal.scm.git;

import com.atlassian.bitbucket.scm.git.GitScmConfig;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.File;

/**
 * Internal extensions to {@link GitScmConfig} which are not intended to be part of the plugin's public API.
 *
 * @since 2.9
 */
public interface InternalGitScmConfig extends GitScmConfig {

    /**
     * Retrieves a {code File} denoting the absolute path to the script that is used to provide passwords for git
     * commands accessing external repositories.
     *
     * @return the absolute path to the script
     * @since 4.6
     */
    File getAskPassScript();

    /**
     * Retrieves the timeout (in seconds) to be applied to commands executed during pull request auto-merges.
     * The auto-merge is used to provide a pull request's diff and diff tree, and to determine whether the pull
     * request can be merged without conflicts.
     *
     * @return the configured auto-merge timeout in seconds
     */
    long getAutoMergeTimeout();

    /**
     * Retrieves the maximum size in number of characters that environment variables can be.
     *
     * @return the maximum size for environment variables
     * @since 4.4
     */
    int getEnvironmentVariableSize();

    /**
     * the minimum time in seconds to wait after an garbage collection triggering event occurs before performing garbage
     * collection.
     *
     * @return the minimum time between a gc trigger and gc execution
     */
    long getGcDelayInSeconds();

    /**
     * The maximum number of times to attempt garbage collection for a repository in case the garbage collection
     * process fails.
     *
     * @return the maximum number of times to attempt garbage collection
     */
    int getGcMaxAttempts();

    /**
     * Defines the maximum number of threads the system will use to perform garbage collection in git repositories. This
     * setting controls how many different repositories can be garbage collected in parallel.
     *
     * @return the maximum number of threads used to perform git garbage collection
     */
    int getGcThreads();

    /**
     * Retrieves the timeout to be applied to repository size calculations, in milliseconds.
     *
     * @return the configured timeout.
     * @since 3.9
     */
    long getSizeTimeout();

    /**
     * Retrieves a {code File} denoting the absolute path to the SSH script that is used for git commands accessing
     * external repositories over SSH.
     *
     * @return the absolute path to the SSH script
     */
    @Nonnull
    File getSshScript();

    /**
     * Retrieves the configured SSH binary to use for git commands accessing external repositories over SSH. The returned
     * value is exactly as configured in the application properties - e.g. if a fully qualified path to the binary is
     * configured, this is returned; if an unqualified path is specified, this is returned.
     *
     * @return the real SSH binary to use for outgoing SSH git operations
     */
    @Nonnull
    String getSshBinary();

    /**
     * Retrieves the configured address where the {@link com.atlassian.stash.internal.scm.git.transcode.DefaultTranscodeServer
     * TranscodeServer} should listen, which may be {@code null} if not configured. In that case, the server listens on
     * localhost (127.0.0.1) by default.
     *
     * @return configured address for the transcode server
     * @since 3.1
     */
    @Nullable
    String getTranscodeAddress();

    /**
     * Retrieves the configured port where the {@link com.atlassian.stash.internal.scm.git.transcode.DefaultTranscodeServer
     * TranscodeServer} should listen. If no explicit port is configured, the JVM will choose one randomly.
     *
     * @return configured port for the transcode server
     * @since 3.1
     */
    int getTranscodePort();

    /**
     * @return whether ref advertisement as part of clones or fetches should be throttled
     */
    boolean isRefAdvertisementThrottled();

    /**
     * Retrieves a flag indicating whether forks should use Git alternates to access objects in their origins. This
     * makes the process of creating forks faster and substantially reduces their storage overhead.
     *
     * @return {@code true} to create shared forks; otherwise, {@code false} to create simple forks
     */
    boolean useAlternates();
}
