package com.atlassian.bitbucket.mesh.boot;

import com.atlassian.bitbucket.mesh.MeshConstants;

import javax.annotation.Nonnull;
import java.util.Optional;

public enum ApplicationMode {

    /**
     * The node should configure itself for use with Bitbucket Cloud.
     */
    CLOUD(MeshConstants.PROFILE_CLOUD, "mesh-cloud.properties"),
    /**
     * The node should configure itself for use as a sidecar process on a Bitbucket Data Center node. This mode
     * means the node will be interacting with repositories in Bitbucket Data Center's shared home and "legacy"
     * (pre-Mesh) {@code DataStore}s.
     */
    SIDECAR(MeshConstants.PROFILE_SIDECAR, "mesh-sidecar.properties"),
    /**
     * The node should configure itself to run as a standalone agent. This mode uses managed repositories that
     * are stored in a Mesh-native way.
     */
    STANDALONE(MeshConstants.PROFILE_STANDALONE, null);

    private final String profile;
    private final String properties;

    ApplicationMode(String profile, String properties) {
        this.profile = profile;
        this.properties = properties;
    }

    /**
     * @return the Spring profile to activate to create any mode-specific beans
     */
    @Nonnull
    public String getProfile() {
        return profile;
    }

    /**
     * @return an optional properties file which should be inserted into the Spring {@code Environment} to adjust
     *         defaults and apply other mode-specific settings
     */
    @Nonnull
    public Optional<String> getProperties() {
        return Optional.ofNullable(properties);
    }
}
