package com.atlassian.bitbucket.mesh.rpc;

import io.grpc.Metadata;

/**
 * Provides constants for metadata keys and documents their usage.
 */
public final class MetadataKeys {

    /**
     * Used to send an identifier for the remote client.
     */
    public static final Metadata.Key<String> KEY_REMOTE_CLIENT =
            Metadata.Key.of("mesh-remote-client", Metadata.ASCII_STRING_MARSHALLER);
    /**
     * Used to send a remote request ID when making a request. This ID is included in the logs, allowing them
     * to be correlated with remote logs related to the same request.
     */
    public static final Metadata.Key<String> KEY_REMOTE_REQUEST =
            Metadata.Key.of("mesh-remote-request", Metadata.ASCII_STRING_MARSHALLER);
    /**
     * Used to send a remote user ID when making a request. This isn't used by the system, since it has no
     * concept of users, but it is included in logs.
     */
    public static final Metadata.Key<String> KEY_REMOTE_USER =
            Metadata.Key.of("mesh-remote-user", Metadata.ASCII_STRING_MARSHALLER);
    /**
     * Used to send the node ID of the intended RPC target. This ID is used to check whether incoming messages
     * were actually intended for this node. If not, the client may be mis-configured, or may be used stale DNS data
     * when resolving the RPC hostname.
     * @since 1.1
     */
    public static final Metadata.Key<String> KEY_TARGET_ID =
            Metadata.Key.of("mesh-target-id", Metadata.ASCII_STRING_MARSHALLER);
    /**
     * Used to send an authentication token when making requests. Requests which don't include the expected
     * token will be rejected without processing.
     */
    public static final Metadata.Key<String> KEY_TOKEN =
            Metadata.Key.of("mesh-token", Metadata.ASCII_STRING_MARSHALLER);

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