package com.atlassian.bitbucket.mesh.config;

import com.atlassian.bitbucket.mesh.annotation.ManagedByControlPlane;

import javax.annotation.Nonnull;
import java.time.Duration;

public interface NodeConfig {

    String UNCONFIGURED_NODE_ID = "-404";

    /**
     * @return how long new requests can block awaiting configuration before they are rejected
     */
    @Nonnull
    Duration getConfigTimeout();

    /**
     * @return the configured ID of this node, which will be {@link #UNCONFIGURED_NODE_ID} if the node has never
     *         received configuration from the control plane
     */
    @ManagedByControlPlane
    @Nonnull
    String getId();

    /**
     * @return the configured name of this node, which will be the hostname if the node has never received
     *         configuration from the control plane
     */
    @ManagedByControlPlane
    @Nonnull
    String getName();

    /**
     * @return the configured URL under which the node's RPC services are accessible, which will set to
     *         {@code http://localhost:<rpc-port>} if the node has never received configuration from the control
     *         plane
     */
    @ManagedByControlPlane
    @Nonnull
    String getRpcUrl();

    /**
     * @return the maximum number of fragments allowed in the sideband's queue before new fragments are dropped
     */
    int getSidebandQueueLimit();

    /**
     * @return {@code true} if new requests should block until the node is configured; otherwise, {@code false} to
     *         allow new requests to be processed without configuration
     */
    boolean isConfigRequired();
}
