package com.atlassian.bitbucket.mesh;

import com.atlassian.bitbucket.mesh.util.Version;
import org.springframework.core.env.Profiles;

public final class MeshConstants {

    /**
     * The lowest RPC API version that this instance still supports.
     */
    public static final Version API_COMPATIBILITY_VERSION = new Version(1, 0);
    /**
     * The current RPC API version.
     * <p>
     * <em>Important:</em> any release that updates the RPC API in any way MUST increment this version.
     * The minor version should be incremented for backwards compatible changes. The major version should
     * be incremented for backwards incompatible changes.
     * <p>
     * When updating the API version, please also describe the changes in {@code API-CHANGELOG.md}.
     */
    public static final Version API_CURRENT_VERSION = new Version(1, 3);

    /**
     * Generic shared thread pool for asynchronous tasks that do not require a dedicated thread pool
     */
    public static final String EXECUTOR_COMMON = "threadpool";
    /**
     * Performs various data store cleanup operations.
     */
    public static final String EXECUTOR_DATASTORE_CLEANUP = "datastore-cleanup";
    /**
     * Performs the various git garbage collection operations.
     */
    public static final String EXECUTOR_GIT_GC = "git-gc";
    /**
     * Processes hook callbacks, such as {@code pre-receive}, for {@code git} processes.
     */
    public static final String EXECUTOR_GIT_HOOK = "git-hook";
    /**
     * Pumps <i>asynchronous</i> processes. Synchronous processes are pumped directly on the calling thread,
     * whatever thread that might be.
     * <p>
     * When a process is run asynchronously, an executor is used to avoid potential pitfalls where one handler
     * performing a blocking operation could delay or deadlock other handlers if pumping used shared threads.
     */
    public static final String EXECUTOR_PROCESS_PUMP = "process-pump";
    /**
     * Runs scheduled tasks to enforce execution and idle timeouts for processes.
     * <p>
     * When external processes ({@code git}) are started, they're given execution and idle timeouts to control
     * how long they can run (with and without producing output, respectively). The associated executor checks
     * processes to detect those which have exceeded their execution or idle timeout and terminate them.
     */
    public static final String EXECUTOR_PROCESS_TIMER = "process-timer";
    /**
     * Performs background repairs of inconsistent repository replicas.
     */
    public static final String EXECUTOR_REPAIR = "repair";
    /**
     * Processes gRPC requests asynchronously, off of the gRPC request thread.
     * <p>
     * The associated executor is used to execute server streaming commands that need to apply backpressure.
     */
    public static final String EXECUTOR_RPC_ASYNC = "grpc-async";
    /**
     * Processes <i>outbound</i> gRPC requests.
     */
    public static final String EXECUTOR_RPC_CLIENT = "grpc-client";
    /**
     * Processes <i>inbound</i> gRPC requests.
     * <p>
     * The associated executor handles new requests when they're received, as well as delivering callbacks and
     * performing other processing related to those requests.
     */
    public static final String EXECUTOR_RPC_SERVER = "grpc-server";
    /**
     * Processes replicated transactions.
     */
    public static final String EXECUTOR_TRANSACTIONS = "tx";
    /**
     * The name of the Spring profile that's enabled when the application runs in cloud mode
     */
    public static final String PROFILE_CLOUD = "cloud";
    /**
     * The name of the Spring profile that's enabled when the application runs as a sidecar
     */
    public static final String PROFILE_SIDECAR = "sidecar";
    /**
     * A negation of {@link #PROFILE_SIDECAR} which can be used with Spring's {@code @Profile} annotation to only
     * create a given bean when the system is <i>not</i> running as a sidecar.
     *
     * @since 1.4.2
     */
    public static final String CONDITION_NOT_SIDECAR = "!" + PROFILE_SIDECAR;
    /**
     * The name of the Spring profile that's enabled when the application runs as a standalone node
     */
    public static final String PROFILE_STANDALONE = "standalone";
    /**
     * The Spring profile that's enabled when the application runs in cloud mode.
     */
    public static final Profiles PROFILES_CLOUD = Profiles.of(PROFILE_CLOUD);
    /**
     * The Spring profile that's enabled when the application runs in sidecar mode.
     */
    public static final Profiles PROFILES_SIDECAR = Profiles.of(PROFILE_SIDECAR);
    /**
     * The Spring profile that's enabled when the application runs in standalone mode.
     */
    public static final Profiles PROFILES_STANDALONE = Profiles.of(PROFILE_STANDALONE);
    /**
     * The version used as the repository version after a repository has been deleted.
     */
    public static final long VERSION_DELETED = Long.MAX_VALUE;

    private MeshConstants() {
        throw new UnsupportedOperationException(getClass() + " is not intended to be instantiated");
    }
}
