"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const commonTypes_1 = require("../commonTypes");
const contractWrapperBase_1 = require("../contractWrapperBase");
const contractWrapperFactory_1 = require("../contractWrapperFactory");
class UpgradeSchemeWrapper extends contractWrapperBase_1.ContractWrapperBase {
    constructor() {
        super(...arguments);
        this.name = "UpgradeScheme";
        this.friendlyName = "Upgrade Scheme";
        this.factory = exports.UpgradeSchemeFactory;
        /**
         * Events
         */
        /* tslint:disable:max-line-length */
        this.NewUpgradeProposal = this.createEventFetcherFactory("NewUpgradeProposal");
        this.ChangeUpgradeSchemeProposal = this.createEventFetcherFactory("ChangeUpgradeSchemeProposal");
        this.ProposalExecuted = this.createEventFetcherFactory("ProposalExecuted");
        this.ProposalDeleted = this.createEventFetcherFactory("ProposalDeleted");
    }
    /* tslint:enable:max-line-length */
    /*******************************************
     * proposeController
     */
    proposeController(options = {}) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            if (!options.avatar) {
                throw new Error("avatar address is not defined");
            }
            if (!options.controller) {
                throw new Error("controller address is not defined");
            }
            this.logContractFunctionCall("UpgradeScheme.proposeUpgrade", options);
            const txResult = yield this.wrapTransactionInvocation("UpgradeScheme.proposeController", options, () => {
                return this.contract.proposeUpgrade(options.avatar, options.controller);
            });
            return new contractWrapperBase_1.ArcTransactionProposalResult(txResult.tx);
        });
    }
    /********************************************
     * proposeUpgradingScheme
     */
    proposeUpgradingScheme(options = {}) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            if (!options.avatar) {
                throw new Error("avatar address is not defined");
            }
            if (!options.scheme) {
                throw new Error("scheme is not defined");
            }
            if (!options.schemeParametersHash) {
                throw new Error("schemeParametersHash is not defined");
            }
            this.logContractFunctionCall("UpgradeScheme.proposeUpgradingScheme", options);
            const txResult = yield this.wrapTransactionInvocation("UpgradeScheme.proposeUpgradingScheme", options, () => {
                return this.contract.proposeChangeUpgradingScheme(options.avatar, options.scheme, options.schemeParametersHash);
            });
            return new contractWrapperBase_1.ArcTransactionProposalResult(txResult.tx);
        });
    }
    setParameters(params) {
        const _super = name => super[name];
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.validateStandardSchemeParams(params);
            return _super("_setParameters").call(this, "UpgradeScheme.setParameters", params.voteParametersHash, params.votingMachineAddress);
        });
    }
    getDefaultPermissions() {
        return commonTypes_1.DefaultSchemePermissions.UpgradeScheme;
    }
    getSchemePermissions(avatarAddress) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            return this._getSchemePermissions(avatarAddress);
        });
    }
    getSchemeParameters(avatarAddress) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            return this._getSchemeParameters(avatarAddress);
        });
    }
    getParameters(paramsHash) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const params = yield this.getParametersArray(paramsHash);
            return {
                voteParametersHash: params[0],
                votingMachineAddress: params[1],
            };
        });
    }
}
exports.UpgradeSchemeWrapper = UpgradeSchemeWrapper;
exports.UpgradeSchemeFactory = new contractWrapperFactory_1.ContractWrapperFactory("UpgradeScheme", UpgradeSchemeWrapper);
//# sourceMappingURL=upgradeScheme.js.map