"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const controllerService_1 = require("./controllerService");
const iContractWrapperBase_1 = require("./iContractWrapperBase");
const schemeWrapperBase_1 = require("./schemeWrapperBase");
/**
 * Abstract base class for all Arc universal scheme contract wrapper classes.  A universal scheme
 * is defined as an Arc scheme (see `SchemeWrapperBase`) that follows the pattern of registering
 * operating parameters with the DAO's controller, thus enabling the contract to be reused across DAOs.
 */
class USchemeWrapperBase extends schemeWrapperBase_1.SchemeWrapperBase {
    /**
     * Given an avatar address, returns the schemes parameters hash
     * @param avatarAddress
     */
    getSchemeParametersHash(avatarAddress) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const controllerService = new controllerService_1.ControllerService(avatarAddress);
            const controller = yield controllerService.getController();
            return controller.getSchemeParameters(this.address, avatarAddress);
        });
    }
    /**
     * Given a hash, returns the associated parameters as an array, ordered by the order
     * in which the parameters appear in the contract's Parameters struct.
     * @param paramsHash
     */
    getParametersArray(paramsHash) {
        return this.contract.parameters(paramsHash);
    }
    _setParameters(functionName, txEventContext, ...params) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const parametersHash = yield this.contract.getParametersHash(...params);
            const txResult = yield this.wrapTransactionInvocation(functionName, 
            // typically this is supposed to be an object, but here it is an array
            Object.assign(params, { txEventContext }), this.contract.setParameters, params);
            return new iContractWrapperBase_1.ArcTransactionDataResult(txResult.tx, this.contract, parametersHash);
        });
    }
    _getSchemeParameters(avatarAddress) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const paramsHash = yield this.getSchemeParametersHash(avatarAddress);
            return this.getParameters(paramsHash);
        });
    }
    _getParametersHash(...params) {
        return this.contract.getParametersHash(...params);
    }
    validateStandardSchemeParams(params) {
        if (!params.voteParametersHash) {
            throw new Error(`voteParametersHash is not defined`);
        }
        if (!params.votingMachineAddress) {
            throw new Error(`votingMachineAddress is not defined`);
        }
    }
}
exports.USchemeWrapperBase = USchemeWrapperBase;
//# sourceMappingURL=uSchemeWrapperBase.js.map