'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _regenerator = require('babel-runtime/regenerator');

var _regenerator2 = _interopRequireDefault(_regenerator);

var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');

var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);

var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');

var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _MiniMeToken = require('minimetoken/build/MiniMeToken.sol');

var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

var _ContractImplementation = require('../../ContractImplementation');

var _ContractImplementation2 = _interopRequireDefault(_ContractImplementation);

var _deployContractAsync = require('../../../utils/deployContractAsync');

var _deployContractAsync2 = _interopRequireDefault(_deployContractAsync);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * Provides interaction with a PinakionPOC contract deployed on the blockchain.
 */
var TokenFactory = function (_ContractImplementati) {
  (0, _inherits3.default)(TokenFactory, _ContractImplementati);

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

    var artifact = {
      abi: _MiniMeToken.MiniMeTokenFactoryAbi,
      bytecode: _MiniMeToken.MiniMeTokenFactoryByteCode
    };
    return (0, _possibleConstructorReturn3.default)(this, (TokenFactory.__proto__ || (0, _getPrototypeOf2.default)(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;
}(_ContractImplementation2.default);

TokenFactory.deploy = function () {
  var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(account, web3Provider) {
    var artifact, contractDeployed;
    return _regenerator2.default.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            artifact = {
              abi: _MiniMeToken.MiniMeTokenFactoryAbi,
              bytecode: _MiniMeToken.MiniMeTokenFactoryByteCode
            };
            _context.next = 3;
            return (0, _deployContractAsync2.default)(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, undefined);
  }));

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

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