"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const bignumber_js_1 = require("bignumber.js");
const contractWrapperFactory_1 = require("../contractWrapperFactory");
const utils_1 = require("../utils");
const web3EventService_1 = require("../web3EventService");
const locking4Reputation_1 = require("./locking4Reputation");
class LockingEth4ReputationWrapper extends locking4Reputation_1.Locking4ReputationWrapper {
    constructor() {
        super(...arguments);
        this.name = "LockingEth4Reputation";
        this.friendlyName = "Locking Eth For Reputation";
        this.factory = exports.LockingEth4ReputationFactory;
    }
    initialize(options) {
        const _super = name => super[name];
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield _super("_initialize").call(this, options);
            this.logContractFunctionCall("LockingEth4Reputation.initialize", options);
            return this.wrapTransactionInvocation("LockingEth4Reputation.initialize", options, this.contract.initialize, [options.avatarAddress,
                options.reputationReward,
                options.lockingStartTime.getTime() / 1000,
                options.lockingEndTime.getTime() / 1000,
                options.redeemEnableTime.getTime() / 1000,
                options.maxLockingPeriod]);
        });
    }
    release(options) {
        const _super = name => super[name];
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield _super("_release").call(this, options);
            this.logContractFunctionCall("LockingEth4Reputation.release", options);
            return this.wrapTransactionInvocation("LockingEth4Reputation.release", options, this.contract.release, [options.lockerAddress, options.lockId]);
        });
    }
    /**
     * Returns reason why can't lock, else null if can lock
     */
    getLockBlocker(options) {
        const _super = name => super[name];
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const msg = yield _super("getLockBlocker").call(this, options);
            if (msg) {
                return msg;
            }
            const balance = yield utils_1.Utils.getEthBalance(options.lockerAddress);
            const amount = new bignumber_js_1.default(options.amount);
            if (balance.lt(amount)) {
                return "the account has insufficient balance";
            }
            return null;
        });
    }
    lock(options) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const msg = yield this.getLockBlocker(options);
            if (msg) {
                throw new Error(msg);
            }
            this.logContractFunctionCall("LockingEth4Reputation.lock", options);
            return this.wrapTransactionInvocation("LockingEth4Reputation.lock", options, this.contract.lock, [options.period], { from: options.lockerAddress, value: options.amount });
        });
    }
}
exports.LockingEth4ReputationWrapper = LockingEth4ReputationWrapper;
class LockingEth4ReputationType extends contractWrapperFactory_1.ContractWrapperFactory {
    deployed() {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            throw new Error("LockingEth4Reputation has not been deployed");
        });
    }
}
exports.LockingEth4ReputationType = LockingEth4ReputationType;
exports.LockingEth4ReputationFactory = new LockingEth4ReputationType("LockingEth4Reputation", LockingEth4ReputationWrapper, new web3EventService_1.Web3EventService());
//# sourceMappingURL=lockingEth4Reputation.js.map