contract ACOCoin is PausableToken {

  using SafeMath for uint256;
  string public constant name = "ACOCoin";
  string public constant symbol = "ACO";
  uint8 public constant decimals = 18;

  uint256 public constant initialSupply_ = 1000000000 * (10 ** uint256(decimals));
  uint256 public tokensForPublicSale = 200000000 * (10 ** 18);
  uint256 public pricePerToken = (10 ** 16); //1 Eth = 1 ACO 

  uint256 minETH = 0 * (10**18); // 0 ether
  uint256 maxETH = 1000 * (10**18); // 10 ether
  
  //Crowdsale running
  bool public isCrowdsaleOpen=false;
  
  /**
   * @dev Constructor that gives msg.sender all of existing tokens.
   */
  constructor() public {
    totalSupply_ = initialSupply_;
    balances[msg.sender] = balances[msg.sender].add(initialSupply_);
    emit Transfer(address(0), msg.sender, initialSupply_);
  }
  
   function startCrowdSale() public onlyOwner {
     isCrowdsaleOpen=true;
  }

   function stopCrowdSale() public onlyOwner {
     isCrowdsaleOpen=false;
  }
  
  function sendToInvestor(address _to, uint256 _value) public onlyOwner {
    transfer(_to, _value);
  }

//tokensForPublicSale should be less than the balance of the owner
//be careful with this function
//should be used only if params needto change other than the default settings
  function setPublicSaleParams(uint256 _tokensForPublicSale, uint256 _min, uint256 _max, uint256 _pricePerToken ) public onlyOwner {
    require(_tokensForPublicSale > 0);
    require (_tokensForPublicSale <= totalSupply_);
    require(_pricePerToken > 0);
    require(_min >= 0);
    require(_max > 0);
    pricePerToken = 0; 
    pricePerToken = pricePerToken.add(_pricePerToken);
    tokensForPublicSale = 0;
    tokensForPublicSale = tokensForPublicSale.add(_tokensForPublicSale);
    minETH = 0;
    minETH = minETH.add(_min);
    maxETH = 0;
    maxETH = maxETH.add(_max);
 }

  
  function buyTokens() public payable returns(uint tokenAmount) {

    uint256 _tokenAmount;
    uint256 multiplier = (10 ** 18);
    uint256 weiAmount = msg.value;

    require(isCrowdsaleOpen);

    require(weiAmount >= minETH);
    require(weiAmount <= maxETH);

    _tokenAmount =  weiAmount.mul(multiplier).div(pricePerToken);

    require(_tokenAmount > 0);

    //safe sub will automatically handle overflows
    tokensForPublicSale = tokensForPublicSale.sub(_tokenAmount);
    //transfer tokens from owner to payee
    require(_tokenAmount <= balances[owner]);
    balances[owner] = balances[owner].sub(_tokenAmount);
    balances[msg.sender] = balances[msg.sender].add(_tokenAmount);
    emit Transfer(owner, msg.sender, _tokenAmount);
    //send money to the owner
    require(owner.send(weiAmount));

    return _tokenAmount;

  }

  // There is no need for vesting. It will be done manually by manually releasing tokens to certain addresses

  function() public payable {
      buyTokens();
  }

}
/**
 * @title ACOCoin Contract
 */
function setPublicSaleParams(uint256 _tokensForPublicSale, uint256 _min, uint256 _max, uint256 _pricePerToken ) public onlyOwner {
  require(_tokensForPublicSale > 0);
  require (_tokensForPublicSale <= totalSupply_);
  require(_pricePerToken > 0);
  require(_min >= 0);
  require(_max > 0);
  pricePerToken = 0; 
  pricePerToken = pricePerToken.add(_pricePerToken);
  tokensForPublicSale = 0;
  tokensForPublicSale = tokensForPublicSale.add(_tokensForPublicSale);
  minETH = 0;
  minETH = minETH.add(_min);
  maxETH = 0;
  maxETH = maxETH.add(_max);


//tokensForPublicSale should be less than the balance of the owner
//be careful with this function
//should be used only if params needto change other than the default settings