/*
 * 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 java.util.Arrays;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.scytl.ov.mixing.commons.concurrent.LoopParallelizerAction;
import com.scytl.ov.mixing.commons.concurrent.processor.PublicCommitmentCalculatorProcess;
import com.scytl.ov.mixing.commons.proofs.bg.commitments.PrivateCommitment;
import com.scytl.ov.mixing.commons.proofs.bg.commitments.PublicCommitment;
import com.scytl.ov.mixing.commons.tools.LoopTools;
import com.scytl.ov.mixing.commons.tools.LoopTools.Range;

/**
 * Encapsulates the initial message generated by a {@link HadamardProductProofGenerator}.
 */
public final class HadamardProductProofInitialMessage {

    private final PublicCommitment[] cB;

    @JsonCreator
    public HadamardProductProofInitialMessage(@JsonProperty("commitmentPublicB") final PublicCommitment[] cB) {
        this.cB = cB;
    }

    public HadamardProductProofInitialMessage(final PrivateCommitment[] cB) {

        final int length = cB.length;
        // Ideally, the number of tasks should be independent from the number of
        // processors. In this case we use it this way to calculate the ranges.
        final List<Range> ranges = LoopTools.asRangesList(length, 1);

        this.cB = new PublicCommitment[cB.length];
        final PublicCommitmentCalculatorProcess process = new PublicCommitmentCalculatorProcess(this.cB, cB);

        new LoopParallelizerAction(process, ranges).invoke();
    }

    /**
     * @return Returns the cB.
     */
    public PublicCommitment[] getCommitmentPublicB() {
        return this.cB;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("HadamardProductProofInitialMessage [_cB=");
        builder.append(Arrays.toString(this.cB));
        builder.append("]");
        return builder.toString();
    }
}
