package meerkat.voting.controller.callbacks;

import meerkat.protobuf.Voting.UIElement;
import meerkat.voting.controller.commands.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * This callback is attached to requests to UI which ask the voter to wait for some process to finish.
 * It actually asks nothing in the UI, and it is simply attached to the UI request as a place-holder.
 * Therefore its onSuccess() method is empty
 */
public class WaitForFinishCallback extends ControllerCallback<Void> {
    protected final static Logger logger = LoggerFactory.getLogger(WaitForFinishCallback.class);
    protected final UIElement somethingWrongMessage;

    public WaitForFinishCallback(int requestId,
                                 long ballotSerialNumber,
                                 LinkedBlockingQueue<ControllerCommand> controllerQueue,
                                 UIElement somethingWrongMessage) {
        super(requestId, ballotSerialNumber, controllerQueue);
        this.somethingWrongMessage = somethingWrongMessage;
    }

    @Override
    public void onSuccess(Void v) {
    }

    @Override
    public void onFailure(Throwable t) {
        logger.error("WaitForFinishCallback got a failure: " + t);
        enqueueCommand(new ReportErrorCommand(getRequestIdentifier(),
                getBallotSerialNumber(),
                somethingWrongMessage));
    }
}
