"use strict";
/* tslint:disable class-name */
Object.defineProperty(exports, "__esModule", { value: true });
const VotersRule_1 = require("../../../../rules/VotersRule");
const ValidationException_1 = require("../../../../validation/ValidationException");
// "one of" mode (every post voter must be within this list)
// "none of" aka blacklist mode (none of post voters can be on this list)
// the post should have all of the specified voters
// the post should have at least one of the specified voters
function wise_rule_voters_encode(r) {
    let mode;
    if (r.mode === VotersRule_1.VotersRule.Mode.ALL)
        mode = "all";
    else if (r.mode === VotersRule_1.VotersRule.Mode.ANY)
        mode = "any";
    else if (r.mode === VotersRule_1.VotersRule.Mode.ONE)
        mode = "one";
    else if (r.mode === VotersRule_1.VotersRule.Mode.NONE)
        mode = "none";
    else
        throw new ValidationException_1.ValidationException("VotersRule: unknown mode " + r.mode);
    const out = {
        rule: "voters",
        mode: mode,
        usernames: r.usernames
    };
    return out;
}
exports.wise_rule_voters_encode = wise_rule_voters_encode;
function wise_rule_voters_decode(r) {
    let mode;
    if (r.mode === "all")
        mode = VotersRule_1.VotersRule.Mode.ALL;
    else if (r.mode === "any")
        mode = VotersRule_1.VotersRule.Mode.ANY;
    else if (r.mode === "one")
        mode = VotersRule_1.VotersRule.Mode.ONE;
    else if (r.mode === "none")
        mode = VotersRule_1.VotersRule.Mode.NONE;
    else
        throw new ValidationException_1.ValidationException("v2:wise_rule_voters: unknown mode " + r.mode);
    return new VotersRule_1.VotersRule(mode, r.usernames);
}
exports.wise_rule_voters_decode = wise_rule_voters_decode;
//# sourceMappingURL=rule-voters-schema.js.map