syntax = "proto3";

package meerkat;

import 'meerkat/crypto.proto';

option java_package = "meerkat.protobuf";



// Type of the element data to be presented by UI
enum UIElementDataType {
    TEXT = 0;
    IMAGE = 1;
    VOICE = 2;
}

// Type of question
enum QuestionType {
    MULTIPLE_CHOICE = 0;
    MULTIPLE_SELECTION = 1;
    ORDER = 2;
}

// An element to be presented by UI
message UIElement {
    UIElementDataType type = 1;
    bytes data = 2;
}

// A question in the ballot
// is_mandatory determines whether the question may be skipped with no answer
// description might hold information/guidlines for the voter
message BallotQuestion {
    bool is_mandatory = 1;
    UIElement question = 2;
    UIElement description = 3;
    repeated UIElement answer = 4;
}


message QuestionCluster {
    UIElement cluster_description = 1;
    repeated int32 question_index = 2;

}

message Channel {
    UIElement channel_description = 1;
    repeated int32 cluster_index = 2;

}

// An answer to a specific ballot question.
// The answer is a vector of signed integers,
// to encompass voting schemes such as ranked voting
// and STV.
message BallotAnswer {
    repeated sint64 answer = 1 [packed=true];
}

message PlaintextBallot {
    uint64 serial_number = 1; // Ballot serial number
    bytes channel_identifier = 2;
    repeated BallotAnswer answers = 3;
}

message EncryptedBallot {
    uint64 serial_number = 1; // Ballot serial number

    RerandomizableEncryptedMessage data = 2;
}

message SignedEncryptedBallot {
    EncryptedBallot encrypted_ballot = 1;
    Signature signature = 2;
}

message BallotSecrets {
    PlaintextBallot plaintext_ballot = 1;

    EncryptionRandomness encryption_randomness = 2;
    RandomnessGenerationProof proof = 3;
}

message BoothParams {
    repeated SignatureVerificationKey pscVerificationKeys = 1;

}

message BoothSystemMessages {
    map<string, UIElement> system_message = 1;
}

// A table to translate to and from compactly encoded answers
// and their human-understandable counterparts.
// This should be parsable by the UI
message BallotAnswerTranslationTable {
    bytes data = 1;
}

// Data required in order to access the Bulletin Board Servers
message BulletinBoardClientParams {

    // Addresses of all Bulletin Board Servers
    repeated string bulletinBoardAddress = 1;

    // Threshold fraction of successful servers posts before a post task is considered complete
    float minRedundancy = 2;
}

message ElectionParams {
    // TODO: different sets of keys for different roles?
    repeated SignatureVerificationKey trusteeVerificationKeys = 1;

    // How many trustees must participate in a signature for it to be considered valid.
    uint32 trusteeSignatureThreshold = 2;

    // The key used to encrypt ballots. The corresponding private key
    // is shared between the trustees.
    EncryptionPublicKey ballotEncryptionKey = 3;

    // Verification keys for valid mixers.
    repeated SignatureVerificationKey mixerVerificationKeys = 4;

    // How many mixers must participate for the network to be considered valid
    uint32 mixerThreshold = 5;

    // questions to first indicate the voter's channel
    repeated BallotQuestion channel_choice_questions = 6;

    // translating the channel-choice answers to the voter's channel
    SimpleCategoriesSelectionData selection_data = 7;

    // Candidate list (or other question format)
    repeated BallotQuestion race_questions = 8;

    // Data required in order to access the Bulletin Board Servers
    BulletinBoardClientParams bulletinBoardClientParams = 9;
}

message Category {
    repeated uint32 questionIndex = 1;
}

message CategoryChooser {
    repeated Category category = 1;
}

message SimpleCategoriesSelectionData {
    Category shared_defaults = 1;
    repeated CategoryChooser categoryChooser = 2;
}

