package meerkat.crypto.dkg.feldman;

import meerkat.comm.Channel;
import meerkat.protobuf.DKG;

import static meerkat.crypto.dkg.comm.MessageUtils.createMessage;

/**
 * Created by Tzlil on 3/14/2016.
 */
public class DKGUserImplAbort<T> extends User<T> {

    final int abortStage;
    int stage;
    public DKGUserImplAbort(Protocol<T> dkg, Channel channel, int abortStage) {
        super(dkg, channel);
        this.abortStage = abortStage;// 1 - 2
        this.stage = 1;
    }


    private void sendAbort(){
        channel.broadcastMessage(createMessage(DKG.Payload.Type.ABORT));
    }

    @Override
    protected void stage1() {
        if(stage < abortStage)
            super.stage1();
        else if(stage == abortStage){
            sendAbort();
        }
        stage++;
    }

    @Override
    protected void stage2() {
        if(stage < abortStage)
            super.stage2();
        else if(stage == abortStage){
            sendAbort();
        }
        stage++;
    }

    @Override
    protected void stage3() {
        if(stage < abortStage)
            super.stage3();
        else if(stage == abortStage){
            sendAbort();
        }
        stage++;
    }

    @Override
    protected void stage4() {
        if(stage < abortStage)
            super.stage4();
        else if(stage == abortStage){
            sendAbort();
        }
        stage++;
    }
}
