"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const contractWrapperBase_1 = require("../contractWrapperBase");
const contractWrapperFactory_1 = require("../contractWrapperFactory");
class AbsoluteVoteWrapper extends contractWrapperBase_1.ContractWrapperBase {
    constructor() {
        super(...arguments);
        this.name = "AbsoluteVote";
        this.friendlyName = "Absolute Vote";
        this.factory = exports.AbsoluteVoteFactory;
        /**
         * Events
         */
        /* tslint:disable:max-line-length */
        this.NewProposal = this.createEventFetcherFactory("NewProposal");
        this.CancelProposal = this.createEventFetcherFactory("CancelProposal");
        this.ExecuteProposal = this.createEventFetcherFactory("ExecuteProposal");
        this.VoteProposal = this.createEventFetcherFactory("VoteProposal");
        this.CancelVoting = this.createEventFetcherFactory("CancelVoting");
    }
    /* tslint:enable:max-line-length */
    /**
     * Vote on a proposal
     * @param {VoteConfig} options
     * @returns Promise<ArcTransactionResult>
     */
    vote(options = {}) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const defaults = {
                onBehalfOf: null,
            };
            options = Object.assign({}, defaults, options);
            if (!options.proposalId) {
                throw new Error("proposalId is not defined");
            }
            if (!Number.isInteger(options.vote) || (options.vote < 0) || (options.vote > 2)) {
                throw new Error("vote is not valid");
            }
            this.logContractFunctionCall("AbsoluteVote.vote", options);
            return this.wrapTransactionInvocation("AbsoluteVote.vote", options, () => {
                return this.contract.vote(options.proposalId, options.vote, options.onBehalfOf ? { from: options.onBehalfOf } : undefined);
            });
        });
    }
    setParameters(params) {
        const _super = name => super[name];
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            params = Object.assign({}, {
                ownerVote: true,
                votePerc: 50,
            }, params);
            if (!params.reputation) {
                throw new Error("reputation must be set");
            }
            return _super("_setParameters").call(this, "AbsoluteVote.setParameters", params.reputation, params.votePerc, params.ownerVote);
        });
    }
    getParameters(paramsHash) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const params = yield this.getParametersArray(paramsHash);
            return {
                ownerVote: params[2],
                reputation: params[0],
                votePerc: params[1].toNumber(),
            };
        });
    }
}
exports.AbsoluteVoteWrapper = AbsoluteVoteWrapper;
exports.AbsoluteVoteFactory = new contractWrapperFactory_1.ContractWrapperFactory("AbsoluteVote", AbsoluteVoteWrapper);
//# sourceMappingURL=absoluteVote.js.map