package meerkat.mixer.necessary;

import meerkat.comm.CommunicationException;
import meerkat.protobuf.Voting.BulletinBoardClientParams;

import java.util.List;

import static meerkat.protobuf.BulletinBoardApi.*;

/**
 * Created by talm on 24/10/15.
 *
 * ToDo: this should be replaced by BulletinBoardClient at BB project
 */
public interface BulletinBoardClient {

    interface ClientCallback<T> {
        void handleCallback(T msg);
        void handleFailure(Throwable t);
    }

    /**
     * Initialize the client to use some specified servers
     * @param clientParams contains the parameters required for the client setup
     */
    void init(BulletinBoardClientParams clientParams);

    /**
     * Post a message to the bulletin board in a synchronous manner
     * @param msg is the message to be posted
     * @return a unique message ID for the message, that can be later used to retrieve the batch
     * @throws CommunicationException
     */
    MessageID postMessage(BulletinBoardMessage msg) throws CommunicationException;



    /**
     * Check how "safe" a given message is in a synchronous manner
     * @param id is the unique message identifier for retrieval
     * @return a normalized "redundancy score" from 0 (local only) to 1 (fully published)
     */
    float getRedundancy(MessageID id);

    /**
     * Read all messages posted matching the given filter in a synchronous manner
     * Note that if messages haven't been "fully posted", this might return a different
     * set of messages in different calls. However, messages that are fully posted
     * are guaranteed to be included.
     * @param filterList return only messages that match the filters (null means no filtering).
     * @return the list of messages
     */
    List<BulletinBoardMessage> readMessages(MessageFilterList filterList);

    /**
     * Closes all connections, if any.
     * This is msgRecived in a synchronous (blocking) way.
     */
    void close();

}
