"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const contractWrapperBase_1 = require("../contractWrapperBase");
const iContractWrapperBase_1 = require("../iContractWrapperBase");
const contractWrapperFactory_1 = require("../contractWrapperFactory");
const loggingService_1 = require("../loggingService");
const utils_1 = require("../utils");
const web3EventService_1 = require("../web3EventService");
class StandardTokenWrapper extends contractWrapperBase_1.ContractWrapperBase {
    constructor() {
        super(...arguments);
        this.name = "StandardToken";
        this.friendlyName = "Standard Token";
        this.factory = exports.StandardTokenFactory;
    }
    /**
     * Approve transfer of tokens by msg.sender (or `onBehalfOf`if given)
     * from the given "spender".
     * @param options
     */
    approve(options) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const web3 = yield utils_1.Utils.getWeb3();
            if (!options.amount) {
                throw new Error("amount is not defined");
            }
            if (!options.spender) {
                throw new Error("spender is not defined");
            }
            const amount = web3.toBigNumber(options.amount);
            if (amount.eq(0)) {
                loggingService_1.LoggingService.warn("StandardToken.approve: amount is zero.  Doing nothing.");
                return new iContractWrapperBase_1.ArcTransactionResult(null, this.contract);
            }
            this.logContractFunctionCall("StandardToken.approve", options);
            return this.wrapTransactionInvocation("StandardToken.approve", options, this.contract.approve, [options.spender, options.amount], options.onBehalfOf ? { from: options.onBehalfOf } : undefined);
        });
    }
    hydrated() {
        /* tslint:disable:max-line-length */
        this.Approval = this.createEventFetcherFactory(this.contract.Approval);
        /* tslint:enable:max-line-length */
    }
}
exports.StandardTokenWrapper = StandardTokenWrapper;
/**
 * defined just to add good type checking
 */
class StandardTokenFactoryType extends contractWrapperFactory_1.ContractWrapperFactory {
    new(initialAccount, initialBalance) {
        const _super = name => super[name];
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            return _super("new").call(this, initialAccount, initialBalance);
        });
    }
}
exports.StandardTokenFactoryType = StandardTokenFactoryType;
exports.StandardTokenFactory = new StandardTokenFactoryType("StandardToken", StandardTokenWrapper, new web3EventService_1.Web3EventService());
//# sourceMappingURL=standardToken.js.map