"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const contractWrapperFactory_1 = require("../contractWrapperFactory");
const web3EventService_1 = require("../web3EventService");
const locking4Reputation_1 = require("./locking4Reputation");
class ExternalLocking4ReputationWrapper extends locking4Reputation_1.Locking4ReputationWrapper {
    constructor() {
        super(...arguments);
        this.name = "ExternalLocking4Reputation";
        this.friendlyName = "External Locking For Reputation";
        this.factory = exports.ExternalLocking4ReputationFactory;
    }
    initialize(options) {
        const _super = name => super[name];
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield _super("_initialize").call(this, options, false);
            if (!options.externalLockingContract) {
                throw new Error("externalLockingContract is not defined");
            }
            if (!options.getBalanceFuncSignature) {
                throw new Error("getBalanceFuncSignature is not defined");
            }
            this.logContractFunctionCall("ExternalLocking4Reputation.initialize", options);
            return this.wrapTransactionInvocation("ExternalLocking4Reputation.initialize", options, this.contract.initialize, [options.avatarAddress,
                options.reputationReward,
                options.lockingStartTime.getTime() / 1000,
                options.lockingEndTime.getTime() / 1000,
                options.redeemEnableTime.getTime() / 1000,
                options.externalLockingContract,
                options.getBalanceFuncSignature]);
        });
    }
    getLockBlocker(options) {
        const _super = name => super[name];
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            /**
             * stub out amount and period -- they aren't relevant to external locking validation.
             */
            const msg = yield _super("getLockBlocker").call(this, Object.assign({}, options, { amount: "1", period: 1 }));
            if (msg) {
                return msg;
            }
            if (!options.lockerAddress) {
                return "lockerAddress is not defined";
            }
            const alreadyLocked = yield this.getAccountHasLocked(options.lockerAddress);
            if (alreadyLocked) {
                return "this account has already executed a lock";
            }
        });
    }
    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("ExternalLocking4Reputation.lock", options);
            return this.wrapTransactionInvocation("ExternalLocking4Reputation.lock", options, this.contract.lock, [], { from: options.lockerAddress });
        });
    }
    getExternalLockingContract() {
        this.logContractFunctionCall("ExternalLocking4Reputation.externalLockingContract");
        return this.contract.externalLockingContract();
    }
    getGetBalanceFuncSignature() {
        this.logContractFunctionCall("ExternalLocking4Reputation.getBalanceFuncSignature");
        return this.contract.getBalanceFuncSignature();
    }
    /**
     * Promise of `true` if the given account has already executed a lock
     */
    getAccountHasLocked(lockerAddress) {
        if (!lockerAddress) {
            throw new Error("lockerAddress is not defined");
        }
        this.logContractFunctionCall("ExternalLocking4Reputation.externalLockers");
        return this.contract.externalLockers(lockerAddress);
    }
}
exports.ExternalLocking4ReputationWrapper = ExternalLocking4ReputationWrapper;
class ExternalLocking4ReputationType extends contractWrapperFactory_1.ContractWrapperFactory {
    deployed() {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            throw new Error("ExternalLocking4Reputation has not been deployed");
        });
    }
}
exports.ExternalLocking4ReputationType = ExternalLocking4ReputationType;
exports.ExternalLocking4ReputationFactory = new ExternalLocking4ReputationType("ExternalLocking4Reputation", ExternalLocking4ReputationWrapper, new web3EventService_1.Web3EventService());
//# sourceMappingURL=externalLocking4Reputation.js.map