"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 commonTypes_1 = require("../commonTypes");
const contractWrapperBase_1 = require("../contractWrapperBase");
const contractWrapperFactory_1 = require("../contractWrapperFactory");
class GlobalConstraintRegistrarWrapper extends contractWrapperBase_1.ContractWrapperBase {
    constructor() {
        super(...arguments);
        this.name = "GlobalConstraintRegistrar";
        this.frendlyName = "Global Constraint Registrar";
        this.factory = exports.GlobalConstraintRegistrarFactory;
        /**
         * Events
         */
        /* tslint:disable:max-line-length */
        this.NewGlobalConstraintsProposal = this.createEventFetcherFactory("NewGlobalConstraintsProposal");
        this.RemoveGlobalConstraintsProposal = this.createEventFetcherFactory("RemoveGlobalConstraintsProposal");
        this.ProposalExecuted = this.createEventFetcherFactory("ProposalExecuted");
        this.ProposalDeleted = this.createEventFetcherFactory("ProposalDeleted");
    }
    /* tslint:enable:max-line-length */
    proposeToAddModifyGlobalConstraint(opts = {}) {
        return __awaiter(this, void 0, void 0, function* () {
            const defaults = {
                /**
                 * avatar address
                 */
                avatar: undefined,
                /**
                 *  the address of the global constraint to add
                 */
                globalConstraint: undefined,
                /**
                 * hash of the parameters of the global contraint
                 */
                globalConstraintParametersHash: undefined,
                /**
                 * voting machine to use when voting to remove the global constraint
                 */
                votingMachineHash: undefined,
            };
            const options = dopts(opts, defaults, { allowUnknown: true });
            if (!options.avatar) {
                throw new Error("address is not defined");
            }
            if (!options.globalConstraint) {
                throw new Error("globalConstraint is not defined");
            }
            if (!options.globalConstraintParametersHash) {
                throw new Error("globalConstraintParametersHash is not defined");
            }
            if (!options.votingMachineHash) {
                throw new Error("votingMachineHash is not defined");
            }
            const tx = yield this.contract.proposeGlobalConstraint(options.avatar, options.globalConstraint, options.globalConstraintParametersHash, options.votingMachineHash);
            return new contractWrapperBase_1.ArcTransactionProposalResult(tx);
        });
    }
    proposeToRemoveGlobalConstraint(opts = {}) {
        return __awaiter(this, void 0, void 0, function* () {
            const defaults = {
                /**
                 * avatar address
                 */
                avatar: undefined,
                /**
                 *  the address of the global constraint to remove
                 */
                globalConstraint: undefined,
            };
            const options = dopts(opts, defaults, { allowUnknown: true });
            if (!options.avatar) {
                throw new Error("avatar address is not defined");
            }
            if (!options.globalConstraint) {
                throw new Error("avatar globalConstraint is not defined");
            }
            const tx = yield this.contract.proposeToRemoveGC(options.avatar, options.globalConstraint);
            return new contractWrapperBase_1.ArcTransactionProposalResult(tx);
        });
    }
    setParameters(params) {
        const _super = name => super[name];
        return __awaiter(this, void 0, void 0, function* () {
            this.validateStandardSchemeParams(params);
            return _super("setParameters").call(this, params.voteParametersHash, params.votingMachineAddress);
        });
    }
    getDefaultPermissions(overrideValue) {
        // return overrideValue || Utils.numberToPermissionsString(DefaultSchemePermissions.GlobalConstraintRegistrar);
        return (overrideValue || commonTypes_1.DefaultSchemePermissions.GlobalConstraintRegistrar);
    }
    getSchemePermissions(avatarAddress) {
        return __awaiter(this, void 0, void 0, function* () {
            return this._getSchemePermissions(avatarAddress);
        });
    }
    getSchemeParameters(avatarAddress) {
        return __awaiter(this, void 0, void 0, function* () {
            return this._getSchemeParameters(avatarAddress);
        });
    }
    getParameters(paramsHash) {
        return __awaiter(this, void 0, void 0, function* () {
            const params = yield this.getParametersArray(paramsHash);
            return {
                voteParametersHash: params[0],
                votingMachineAddress: params[1],
            };
        });
    }
}
exports.GlobalConstraintRegistrarWrapper = GlobalConstraintRegistrarWrapper;
exports.GlobalConstraintRegistrarFactory = new contractWrapperFactory_1.default("GlobalConstraintRegistrar", GlobalConstraintRegistrarWrapper);
//# sourceMappingURL=globalconstraintregistrar.js.map