"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const dopts = require("default-options");
const contractWrapperBase_1 = require("../contractWrapperBase");
const contractWrapperFactory_1 = require("../contractWrapperFactory");
class AbsoluteVoteWrapper extends contractWrapperBase_1.ContractWrapperBase {
    constructor() {
        super(...arguments);
        this.name = "AbsoluteVote";
        this.frendlyName = "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} opts
     * @returns Promise<ArcTransactionResult>
     */
    vote(opts = {}) {
        return __awaiter(this, void 0, void 0, function* () {
            const defaults = {
                onBehalfOf: null,
                proposalId: undefined,
                vote: undefined,
            };
            const options = dopts(opts, defaults, { allowUnknown: true });
            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");
            }
            const tx = yield this.contract.vote(options.proposalId, options.vote, options.onBehalfOf ? { from: options.onBehalfOf } : undefined);
            return new contractWrapperBase_1.ArcTransactionResult(tx);
        });
    }
    setParameters(params) {
        const _super = name => super[name];
        return __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, params.reputation, params.votePerc, params.ownerVote);
        });
    }
    getParameters(paramsHash) {
        return __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.default("AbsoluteVote", AbsoluteVoteWrapper);
//# sourceMappingURL=absoluteVote.js.map