contract NLCToken is StandardToken {
    ///
    using SafeMath for uint256;

    ///
    string public constant name = "Nutrilife OU";
    string public constant symbol = "NLC";
    uint8 public constant decimals = 18;  
    
    /// The owner of this address will distrbute the locked and vested tokens
    address public nlcAdminAddress;
    uint256 public weiRaised;
    uint256 public rate;

    modifier onlyAdmin {
        require(msg.sender == nlcAdminAddress);
        _;
    }
    
    /**
    * Event for token purchase logging
    * @param investor invest into the token
    * @param value weis paid for purchase
    */
    event Investment(address indexed investor, uint256 value);
    event TokenPurchaseRequestFromInvestment(address indexed investor, uint256 token);
    event ApproveTokenPurchaseRequest(address indexed investor, uint256 token);
    
    /// Initial tokens to be allocated (500 million)
    uint256 public constant INITIAL_SUPPLY = 500000000 * 10**uint256(decimals);
    mapping(address => uint256) public _investorsVault;
    mapping(address => uint256) public _investorsInvestmentInToken;

    ///
    constructor(address _nlcAdminAddress, uint256 _rate) public {
        require(_nlcAdminAddress != address(0));
        
        nlcAdminAddress = _nlcAdminAddress;
        totalSupply_ = INITIAL_SUPPLY;
        rate = _rate;

        balances[_nlcAdminAddress] = totalSupply_;
    }


    /**
    * @dev fallback function ***DO NOT OVERRIDE***
    */
    function () external payable {
        investFund(msg.sender);
    }

    /**
      * @dev low level token purchase ***DO NOT OVERRIDE***
      * @param _investor Address performing the token purchase
      */
    function investFund(address _investor) public payable {
        //
        uint256 weiAmount = msg.value;
        
        _preValidatePurchase(_investor, weiAmount);
        
        weiRaised = weiRaised.add(weiAmount);
        
        _trackVault(_investor, weiAmount);
        
        _forwardFunds();

        emit Investment(_investor, weiAmount);
    }
    
    /**
    * @dev Gets the invested fund specified address.
    * @param _investor The address to query the the balance of invested amount.
    * @return An uint256 representing the invested amount by the passed address.
    */
    function investmentOf(address _investor) public view returns (uint256) {
        return _investorsVault[_investor];
    }

    /**
    * @dev token request from invested ETH.
    * @param _ethInWei investor want to invest ether amount.
    * @return An uint256 representing the invested amount by the passed address.
    */
    function purchaseTokenFromInvestment(uint256 _ethInWei) public {
            ///
            require(_investorsVault[msg.sender] != 0);

            ///
            uint256 _token = _getTokenAmount(_ethInWei);
            
            _investorsVault[msg.sender] = _investorsVault[msg.sender].sub(_ethInWei);

            _investorsInvestmentInToken[msg.sender] = _investorsInvestmentInToken[msg.sender].add(_token);
            
            emit TokenPurchaseRequestFromInvestment(msg.sender, _token);
    }

    /**
    * @dev Gets the investment token request for token.
    * @param _investor The address to query the the balance of invested amount.
    * @return An uint256 representing the invested amount by the passed address.
    */
    function tokenInvestmentRequest(address _investor) public view returns (uint256) {
        return _investorsInvestmentInToken[_investor];
    }

    /**
    * @dev Gets the invested fund specified address.
    * @param _investor The address to query the the balance of invested amount.
    * @return An uint256 representing the invested amount by the passed address.
    */
    function approveTokenInvestmentRequest(address _investor) public onlyAdmin {
        //
        uint256 token = _investorsInvestmentInToken[_investor];
        require(token != 0);
        //
        super.transfer(_investor, _investorsInvestmentInToken[_investor]);
        
        _investorsInvestmentInToken[_investor] = _investorsInvestmentInToken[_investor].sub(token);
        
        emit ApproveTokenPurchaseRequest(_investor, token);
    }

   /**
    * @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. Use super to concatenate validations.
    * @param _beneficiary Address performing the token purchase
    * @param _weiAmount Value in wei involved in the purchase
    */
    function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) internal pure {
        require(_beneficiary != address(0));
        require(_weiAmount != 0);
        
        // must be greater than 1/2 ETH.
        require(_weiAmount >= 0.5 ether);
    }

   /**
    * @dev tracing of incoming fund from investors.
    * @param _investor Address performing the token purchase
    * @param _weiAmount Value in wei involved in the purchase
    */
    function _trackVault(address _investor, uint256 _weiAmount) internal {
        _investorsVault[_investor] = _investorsVault[_investor].add(_weiAmount);
    }

    /**
    * @dev Determines how ETH is stored/forwarded on investment.
    */
    function _forwardFunds() internal {
        nlcAdminAddress.transfer(msg.value);
    }

    /**
    * @dev Override to extend the way in which ether is converted to tokens.
    * @param _weiAmount Value in wei to be converted into tokens
    * @return Number of tokens that can be purchased with the specified _weiAmount
    */
    function _getTokenAmount(uint256 _weiAmount)
        internal view returns (uint256)
    {
        return _weiAmount.mul(rate).div(1 ether);
    }

}
/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure.
 * To use this library you can add a `using SafeERC20 for ERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
function investmentOf(address _investor) public view returns (uint256) {
        return _investorsVault[_investor];
    }
/**
 * @dev Gets the invested fund specified address.
 * @param _investor The address to query the the balance of invested amount.
 * @return An uint256 representing the invested amount by the passed address.
 */