/*
 * Copyright 2018 Scytl Secure Electronic Voting SA
 *
 * All rights reserved
 *
 * See our extended copyright notice in *file 'Copyright.txt' which is part of this source code package
 */
package com.scytl.products.ov.mixnet.commons.beans.proofs;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.scytl.products.ov.mixnet.commons.proofs.bg.commitments.PublicCommitment;

/**
 * This class encapsulates the proofs that are generated by the {@link ShuffleProofGenerator}.
 */
public class ShuffleProof {

    private final PublicCommitment[] initialMessage;

    private final PublicCommitment[] firstAnswer;

    private final ShuffleProofSecondAnswer secondAnswer;

    @JsonCreator
    public ShuffleProof(@JsonProperty("initialMessage") final PublicCommitment[] initialMessage,
            @JsonProperty("firstAnswer") final PublicCommitment[] firstAnswer,
            @JsonProperty("secondAnswer") final ShuffleProofSecondAnswer secondAnswer) {

        this.initialMessage = initialMessage;
        this.firstAnswer = firstAnswer;
        this.secondAnswer = secondAnswer;
    }

    private ShuffleProof(final Builder builder) {
    	this.initialMessage = builder.initMessage;
    	this.firstAnswer = builder.fAnswer;
    	this.secondAnswer = builder.sAnswer;
    }

    public PublicCommitment[] getInitialMessage() {
        return initialMessage;
    }

    public PublicCommitment[] getFirstAnswer() {
        return firstAnswer;
    }

    public ShuffleProofSecondAnswer getSecondAnswer() {
        return secondAnswer;
    }

    public static class Builder {

        private PublicCommitment[] initMessage;

        private PublicCommitment[] fAnswer;

        private ShuffleProofSecondAnswer sAnswer;

        public Builder withInitialMessage(final PublicCommitment[] initialMessage) {
            initMessage = initialMessage;
            return this;
        }

        public Builder withFirstAnswer(final PublicCommitment[] firstAnswer) {
            fAnswer = firstAnswer;
            return this;
        }

        public Builder withSecondAnswer(final ShuffleProofSecondAnswer secondAnswer) {
            sAnswer = secondAnswer;
            return this;
        }

        public ShuffleProof build() {
            checkValues();
            return new ShuffleProof(this);
        }

        private void checkValues() {
            if (initMessage == null) {
                throw new IllegalStateException("Initial message cannot be null");
            }
            if (fAnswer == null) {
                throw new IllegalStateException("First answer cannot be null");
            }
            if (sAnswer == null) {
                throw new IllegalStateException("Second answer cannot be null");
            }
        }
    }
}
