package com.atlassian.bitbucket.mesh.grpc;

import com.atlassian.bitbucket.mesh.rpc.v1.RpcStreamChunk;

import javax.annotation.Nonnull;

/**
 * Defines a mechanism for creating request fragments. The {@link #getInitial initial} fragment is used to start
 * the remote process, and then subsequent fragments provide {@link RpcStreamChunk chunks} of {@code stdin}.
 *
 * @param <ReqT> the fragment request type
 */
public interface RequestFragmentCreator<ReqT> {

    /**
     * Creates a fragment for dispatching the provided {@code stdin} {@link RpcStreamChunk chunk}.
     *
     * @param stdin the {@code stdin} chunk to wrap
     * @return a request fragment for the provided {@code stdin}
     */
    @Nonnull
    ReqT forStdin(@Nonnull RpcStreamChunk stdin);

    /**
     * Creates the initial request, which is used to start the remote process. This will always be sent before
     * any calls to {@link #forStdin}.
     *
     * @return the initial request
     */
    @Nonnull
    ReqT getInitial();
}
