"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const contractWrapperBase_1 = require("../contractWrapperBase");
const bignumber_js_1 = require("bignumber.js");
const contractWrapperFactory_1 = require("../contractWrapperFactory");
const controllerService_1 = require("../controllerService");
const web3EventService_1 = require("../web3EventService");
class TokenCapGCWrapper extends contractWrapperBase_1.ContractWrapperBase {
    constructor() {
        super(...arguments);
        this.name = "TokenCapGC";
        this.friendlyName = "Token Cap Global Constraint";
        this.factory = exports.TokenCapGCFactory;
    }
    getParametersHash(params) {
        return this._getParametersHash(params.token, params.cap || 0);
    }
    setParameters(params) {
        if (!params.token) {
            throw new Error("token must be set");
        }
        const cap = new bignumber_js_1.default(params.cap);
        if (cap.lt(0)) {
            throw new Error("cap must be greater than or equal to zero");
        }
        return super._setParameters("TokenCapGC.setParameters", params.txEventContext, params.token, cap);
    }
    getParameters(paramsHash) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const params = yield this.getParametersArray(paramsHash);
            return {
                cap: params[1],
                token: params[0],
            };
        });
    }
    getRegisteredParametersHash(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.getGlobalConstraintParameters(this.address, avatarAddress);
        });
    }
    getRegisteredParameters(avatarAddress) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const paramsHash = yield this.getRegisteredParametersHash(avatarAddress);
            return this.getParameters(paramsHash);
        });
    }
}
exports.TokenCapGCWrapper = TokenCapGCWrapper;
exports.TokenCapGCFactory = new contractWrapperFactory_1.ContractWrapperFactory("TokenCapGC", TokenCapGCWrapper, new web3EventService_1.Web3EventService());
//# sourceMappingURL=tokenCapGC.js.map