"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const iContractWrapperBase_1 = require("../iContractWrapperBase");
const bignumber_js_1 = require("bignumber.js");
const contractWrapperBase_1 = require("../contractWrapperBase");
const contractWrapperFactory_1 = require("../contractWrapperFactory");
const loggingService_1 = require("../loggingService");
const web3EventService_1 = require("../web3EventService");
class ReputationWrapper extends contractWrapperBase_1.ContractWrapperBase {
    constructor() {
        super(...arguments);
        this.name = "Reputation";
        this.friendlyName = "Reputation";
        this.factory = exports.ReputationFactory;
    }
    /**
     * Mint reputation to the given recipient
     * @param options
     */
    mint(options) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            if (!options.recipient) {
                throw new Error("recipient is not defined");
            }
            const amount = new bignumber_js_1.BigNumber(options.amount);
            if (amount.eq(0)) {
                loggingService_1.LoggingService.warn("Reputation.mint: amount is zero.  Doing nothing.");
                return new iContractWrapperBase_1.ArcTransactionResult(null, this.contract);
            }
            this.logContractFunctionCall("Reputation.mint", options);
            return this.wrapTransactionInvocation("Reputation.mint", options, this.contract.mint, [options.recipient, options.amount]);
        });
    }
    /**
     * Remove reputation from the given account.
     * @param options
     */
    burn(options) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            if (!options.from) {
                throw new Error("'from' is not defined");
            }
            const amount = new bignumber_js_1.BigNumber(options.amount);
            if (amount.eq(0)) {
                loggingService_1.LoggingService.warn("Reputation.burn: amount is zero.  Doing nothing.");
                return new iContractWrapperBase_1.ArcTransactionResult(null, this.contract);
            }
            this.logContractFunctionCall("Reputation.burn", options);
            return this.wrapTransactionInvocation("Reputation.burn", options, this.contract.burn, [options.from, options.amount]);
        });
    }
    getTotalSupply() {
        this.logContractFunctionCall("Reputation.totalSupply");
        return this.contract.totalSupply();
    }
    /**
     * Total amount of reputation at the given `blockNumber`.
     */
    getTotalSupplyAt(blockNumber) {
        this.logContractFunctionCall("Reputation.totalSupplyAt");
        return this.contract.totalSupply();
    }
    getBalanceOf(accountAddress) {
        if (!accountAddress) {
            throw new Error("accountAddress is not defined");
        }
        this.logContractFunctionCall("Reputation.balanceOf", accountAddress);
        return this.contract.balanceOf(accountAddress);
    }
    /**
     * Queries the balance of `accountAddress` at the given `blockNumber`
     * @param accountAddress
     * @param blockNumber
     */
    getBalanceOfAt(accountAddress, blockNumber) {
        if (!accountAddress) {
            throw new Error("accountAddress is not defined");
        }
        if (typeof (blockNumber) === "undefined") {
            throw new Error("blockNumber is not defined");
        }
        this.logContractFunctionCall("Reputation.balanceOfAt", { accountAddress, blockNumber });
        return this.contract.balanceOfAt(accountAddress, blockNumber);
    }
    hydrated() {
        /* tslint:disable:max-line-length */
        this.Mint = this.createEventFetcherFactory(this.contract.Mint);
        this.Burn = this.createEventFetcherFactory(this.contract.Burn);
        /* tslint:enable:max-line-length */
    }
}
exports.ReputationWrapper = ReputationWrapper;
class ReputationFactoryType extends contractWrapperFactory_1.ContractWrapperFactory {
    deployed() {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            throw new Error("Reputation has not been deployed");
        });
    }
}
exports.ReputationFactoryType = ReputationFactoryType;
exports.ReputationFactory = new ReputationFactoryType("Reputation", ReputationWrapper, new web3EventService_1.Web3EventService());
//# sourceMappingURL=reputation.js.map