/*
 * 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.ov.mixing.commons.beans.proofs;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.scytl.cryptolib.mathematical.groups.impl.Exponent;

/**
 * This class encapsulates the answer that is generated by the {@link ReductionProofGenerator}.
 */
public class MultiExponentiationReductionAnswer {

    private static final Logger LOG = LoggerFactory.getLogger("std");

    private final Exponent[] b;

    private final Exponent s;

    private final MultiExponentiationBasicProofInitialMessage iniBasic;

    private final MultiExponentiationBasicProofAnswer ansBasic;

    private final MultiExponentiationReductionInitialMessage iniReduct;

    private final MultiExponentiationReductionAnswer ansReduct;

    @JsonCreator
    public MultiExponentiationReductionAnswer(@JsonProperty("exponentsB") final Exponent[] b,
            @JsonProperty("exponentS") final Exponent s,
            @JsonProperty("iniBasic") final MultiExponentiationBasicProofInitialMessage iniBasic,
            @JsonProperty("ansBasic") final MultiExponentiationBasicProofAnswer ansBasic,
            @JsonProperty("iniReduct") final MultiExponentiationReductionInitialMessage iniReduct,
            @JsonProperty("ansReduct") final MultiExponentiationReductionAnswer ansReduct) {
    	this.b = b;
    	this.s = s;
    	this.iniBasic = iniBasic;
    	this.ansBasic = ansBasic;
    	this.iniReduct = iniReduct;
    	this.ansReduct = ansReduct;
    }

    public MultiExponentiationReductionAnswer(final Exponent[] b, final Exponent s,
            final MultiExponentiationBasicProofInitialMessage iniBasic,
            final MultiExponentiationBasicProofAnswer ansBasic) {
    	this.b = b;
    	this.s = s;
    	this.iniBasic = iniBasic;
    	this.ansBasic = ansBasic;
    	this.iniReduct = null;
    	this.ansReduct = null;
    }

    public MultiExponentiationReductionAnswer(final Exponent[] b, final Exponent s,
            final MultiExponentiationReductionInitialMessage iniReduct,
            final MultiExponentiationReductionAnswer ansReduct) {
    	this.b = b;
    	this.s = s;
    	this.iniBasic = null;
    	this.ansBasic = null;
    	this.iniReduct = iniReduct;
    	this.ansReduct = ansReduct;
    }

    /**
     * @return Returns the b.
     */
    public Exponent[] getExponentsB() {
        return b;
    }

    /**
     * @return Returns the s.
     */
    public Exponent getExponentS() {
        return s;
    }

    /**
     * @return Returns the iniBasic.
     */
    public MultiExponentiationBasicProofInitialMessage getIniBasic() {
        return iniBasic;
    }

    /**
     * @return Returns the ansBasic.
     */
    public MultiExponentiationBasicProofAnswer getAnsBasic() {
        return ansBasic;
    }

    /**
     * @return Returns the iniReduct.
     */
    public MultiExponentiationReductionInitialMessage getIniReduct() {
        return iniReduct;
    }

    /**
     * @return Returns the ansReduct.
     */
    public MultiExponentiationReductionAnswer getAnsReduct() {
        return ansReduct;
    }

    @Override
    public String toString() {
        final StringBuilder strbldr = new StringBuilder();
        for (final Exponent a_b : b) {
            strbldr.append(a_b.toString());
        }
        strbldr.append(s.toString());
        if ((iniBasic != null) && (ansBasic != null)) {
            strbldr.append(iniBasic.toString());
            strbldr.append(ansBasic.toString());
        } else if ((iniReduct != null) && (ansReduct != null)) {
            strbldr.append(iniReduct.toString());
            strbldr.append(ansReduct.toString());
        } else {
            // probably not needed due to the constructors
            LOG.error("Error(ToString): answer msg ME reduct not initialized");
        }

        return strbldr.toString();
    }
}
