import _regeneratorRuntime from 'babel-runtime/regenerator';
import _asyncToGenerator from 'babel-runtime/helpers/asyncToGenerator';
import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';

var _this2 = this;

import { MiniMeTokenFactoryAbi, MiniMeTokenFactoryByteCode } from 'minimetoken/build/MiniMeToken.sol';
import _ from 'lodash';

import ContractImplementation from '../../ContractImplementation';
import deployContractAsync from '../../../utils/deployContractAsync';

/**
 * Provides interaction with a PinakionPOC contract deployed on the blockchain.
 */

var TokenFactory = function (_ContractImplementati) {
  _inherits(TokenFactory, _ContractImplementati);

  /**
   * Constructor PinakionPOC.
   * @param {object} web3Provider - web3 instance.
   * @param {string} contractAddress - of the contract (optionnal).
   */
  function TokenFactory(web3Provider, contractAddress) {
    _classCallCheck(this, TokenFactory);

    var artifact = {
      abi: MiniMeTokenFactoryAbi,
      bytecode: MiniMeTokenFactoryByteCode
    };
    return _possibleConstructorReturn(this, (TokenFactory.__proto__ || _Object$getPrototypeOf(TokenFactory)).call(this, web3Provider, artifact, contractAddress));
  }

  /**
   * Deploy a new instance of PinakionPOC.
   * @param {string} account - account of user
   * @param {object} web3Provider - web3 provider object
   * @returns {object} - 'truffle-contract' Object | err The contract object or error deploy.
   */


  return TokenFactory;
}(ContractImplementation);

TokenFactory.deploy = function () {
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(account, web3Provider) {
    var artifact, contractDeployed;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            artifact = {
              abi: MiniMeTokenFactoryAbi,
              bytecode: MiniMeTokenFactoryByteCode
            };
            _context.next = 3;
            return deployContractAsync(account, // account
            0, // value
            artifact, // artifact
            web3Provider // web3
            );

          case 3:
            contractDeployed = _context.sent;
            return _context.abrupt('return', contractDeployed);

          case 5:
          case 'end':
            return _context.stop();
        }
      }
    }, _callee, _this2);
  }));

  return function (_x, _x2) {
    return _ref.apply(this, arguments);
  };
}();

export default TokenFactory;
//# sourceMappingURL=TokenFactory.js.map