package com.atlassian.bitbucket.mesh.config;

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

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.nio.file.Path;
import java.time.Duration;

public interface GrpcConfig {

    /**
     * Controls when server side streaming RPCs should emit the next fragment message.
     *
     * @return the length in bytes at which a 'batch' fragment message should be emitted
     */
    @ManagedByControlPlane
    long getFragmentSize();

    /**
     * @return the lowest value a gRPC client is allowed to use as its keep-alive time
     */
    @ManagedByControlPlane
    @Nonnull
    Duration getKeepAliveTime();

    /**
     * Controls when server side streaming RPCs should emit the next fragment message, when using as few fragments
     * as possible.
     *
     * @return the length in bytes at which a 'batch' fragment message should be emitted
     */
    @ManagedByControlPlane
    long getMaxFragmentSize();

    /**
     * The maximum message size allowed for a single gRPC frame. If an inbound messages larger than this limit is
     * received it will not be processed and the RPC will fail with {@link io.grpc.Status#RESOURCE_EXHAUSTED}.
     *
     * @return the maximum message size in bytes
     */
    @ManagedByControlPlane
    int getMaxMessageSize();

    /**
     * @return the maximum size of metadata allowed to be retrieved for RPC calls
     */
    @ManagedByControlPlane
    int getMaxMetadataSize();

    /**
     * @return the maximum frequency (in Hz) progress fragment messages (e.g. for git push) can be sent.
     */
    int getMaxProgressUpdateFrequency();

    /**
     * @return the hostname the gRPC server should bind to
     */
    @Nonnull
    String getServerAddress();

    /**
     * @return the port to use for the gRPC server
     */
    int getServerPort();

    @ManagedByControlPlane
    @Nonnull
    Duration getServerShutdownTimeout();

    /**
     * @return the path to the SSL certification chain file
     */
    @Nullable
    Path getServerSslCertChainPath();

    /**
     * @return the path to the SSL private key file
     */
    @Nullable
    Path getServerSslPrivateKeyPath();

    /**
     * @return whether clients are allowed to use gRPC keepalive pings to keep the connection to the server open when
     *         no RPC operations to the server are active.
     */
    @ManagedByControlPlane
    boolean isKeepAliveWithoutCallsAllowed();

    /**
     * @return whether the gRPC server should perform a live restart after a change to one of the relevant gRPC
     *         configuration properties is detected
     */
    @ManagedByControlPlane
    boolean isServerRestartOnConfigurationChange();

    /**
     * @return whether zero-copy unmarshalling optimizations are enabled
     */
    @ManagedByControlPlane
    boolean isZeroCopy();
}
