"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 UpgradeSchemeWrapper extends contractWrapperBase_1.ContractWrapperBase {
    constructor() {
        super(...arguments);
        this.name = "UpgradeScheme";
        this.frendlyName = "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(opts = {}) {
        return __awaiter(this, void 0, void 0, function* () {
            const defaults = {
                /**
                 * avatar address
                 */
                avatar: undefined,
                /**
                 *  controller address
                 */
                controller: undefined,
            };
            const options = dopts(opts, defaults, { allowUnknown: true });
            if (!options.avatar) {
                throw new Error("avatar address is not defined");
            }
            if (!options.controller) {
                throw new Error("controller address is not defined");
            }
            const tx = yield this.contract.proposeUpgrade(options.avatar, options.controller);
            return new contractWrapperBase_1.ArcTransactionProposalResult(tx);
        });
    }
    /********************************************
     * proposeUpgradingScheme
     */
    proposeUpgradingScheme(opts = {}) {
        return __awaiter(this, void 0, void 0, function* () {
            /**
             * Note that explicitly supplying any property with a value of undefined will prevent the property
             * from taking on its default value (weird behavior of default-options)
             */
            const defaults = {
                /**
                 * avatar address
                 */
                avatar: undefined,
                /**
                 *  upgrading scheme address
                 */
                scheme: undefined,
                /**
                 * hash of the parameters of the upgrading scheme. These must be already registered with the new scheme.
                 */
                schemeParametersHash: undefined,
            };
            const options = dopts(opts, defaults, { allowUnknown: true });
            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");
            }
            const tx = yield this.contract.proposeChangeUpgradingScheme(options.avatar, options.scheme, options.schemeParametersHash);
            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.UpgradeScheme);
        return (overrideValue || commonTypes_1.DefaultSchemePermissions.UpgradeScheme);
    }
    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.UpgradeSchemeWrapper = UpgradeSchemeWrapper;
exports.UpgradeSchemeFactory = new contractWrapperFactory_1.default("UpgradeScheme", UpgradeSchemeWrapper);
//# sourceMappingURL=upgradescheme.js.map