contract HRS is ERC20, ERC20Detailed, Ownable, ReentrancyGuard  {
   using SafeMath for uint256;
   
   mapping (address => bool) status; 
   
   // Address where funds can be collected
    address private _walletP;
    // Address where funds can be collected too
    address private _walletN;
    // How many token units a buyer gets per wei.
    // The rate is the conversion between wei and the smallest and indivisible token unit.
    // So, if you are using a rate of 1 with a ERC20Detailed token with 3 decimals called TOK
    // 1 wei will give you 1 unit, or 0.001 TOK.
    uint256 private _rate;
    // _rate multiply index
    uint256 private _x;
    // _rate share index
    uint256 private _y;
    // Amount of wei raised
    uint256 private _weiRaised;
    
    /**
     * @dev Constructor that gives msg.sender initialSupply of existing tokens.
     */
    constructor () public ERC20Detailed("HYDROSTANDART", "HRS", 18, 20000000
    ) {
        _mint(msg.sender, initSupply());
    }

   /**
     * @dev Function to mint tokens
     * @param to The address that will receive the minted tokens.
     * @param value The amount of tokens to mint.
     * @return A boolean that indicates if the operation was successful.
     */
    function mint(address to, uint256 value) public onlyOwner returns (bool) {
        _mint(to, value);
        return true;
    }
    
   /**
     * @dev Function to burn tokens
     * @param to The address to burn tokens.
     * @param value The amount of tokens to burn.
     * @return A boolean that indicates if the operation was successful.
     */
    function burn(address to, uint256 value) public onlyOwner returns (bool) {
        _burn(to, value);
        return true;
    }
   /**
     * @dev check an account's status
     * @return bool
     */
    function CheckStatus(address account) public view returns (bool) {
        require(account != address(0));
        bool currentStatus = status[account];
        return currentStatus;
    }
    
    /**
     * @dev change an account's status. OnlyOwner
     * @return bool
     */
    function ChangeStatus(address account) public  onlyOwner {
        require(account != address(0));
        bool currentStatus1 = status[account];
       status[account] = (currentStatus1 == true) ? false : true;
    }

   /**
     * @dev fallback function ***DO NOT OVERRIDE***
     * Note that other contracts will transfer fund with a base gas stipend
     * of 2300, which is not enough to call buyTokens. Consider calling
     * buyTokens directly when purchasing tokens from a contract.
     */
    function () external payable {
        buyTokens(msg.sender, msg.value);
        }
    function buyTokens(address beneficiary, uint256 weiAmount) public nonReentrant payable {
        require(beneficiary != address(0) && beneficiary !=_walletP && beneficiary !=_walletN);
        require(weiAmount != 0);
        require(_walletP != 0);
        require(_walletN != 0);
        require(CheckStatus(beneficiary) != true);
        
        // calculate token amount to be created
        uint256 tokens = weiAmount.div(_y).mul(_x).mul(_rate);
        // compass 
        address CurrentFundWallet = (balanceOf(_walletP) > balanceOf(_walletN) == true) ? _walletP : _walletN;
        // check token amount to be transfered from _wallet
        require(balanceOf(CurrentFundWallet) > tokens);
        // update state
        _weiRaised = _weiRaised.add(weiAmount);
        // transfer tokens to beneficiary from CurrentFundWallet
       _transfer(CurrentFundWallet, beneficiary, tokens);
       // transfer weiAmount to CurrentFundWallet
       CurrentFundWallet.transfer(weiAmount);
    }
  
    /**
     * Set Rate. onlyOwner
     */
    function setRate(uint256 rate) public onlyOwner  {
        require(rate > 1);
        _rate = rate;
    }
    /**
     * Set X. onlyOwner
     */
    function setX(uint256 x) public onlyOwner  {
        require(x >= 1);
        _x = x;
    }
    /**
     * Set Y. onlyOwner
     */
    function setY(uint256 y) public onlyOwner  {
        require(y >= 1);
        _y = y;
    }
    /**
     * Set the Positiv _wallet. onlyOwner
     */
    function setPositivWallet(address PositivWallet) public onlyOwner  {
        _walletP = PositivWallet;
    } 
    
    /**
     * @return the Positiv _wallet.
     */
    function PositivWallet() public view returns (address) {
        return _walletP;
    }
    /**
     * Set the Negativ _wallet. onlyOwner
     */
    function setNegativWallet(address NegativWallet) public onlyOwner  {
        _walletN = NegativWallet;
    } 
    
    /**
     * @return the Negativ _wallet.
     */
    function NegativWallet() public view returns (address) {
        return _walletN;
    }
    /**
     * @return Rate.
     */
    function Rate() public view returns (uint256) {
        return _rate;
    }
    /**
     * @return _X.
     */
    function X() public view returns (uint256) {
        return _x;
    }
    /**
     * @return _Y.
     */
    function Y() public view returns (uint256) {
        return _y;
    }
    /**
     * @return the number of wei income Total.
     */
    function WeiRaised() public view returns (uint256) {
        return _weiRaised;
    }
    
}
/**
 * @title HRS
 * @dev ERC20 Token 
 */
function NegativWallet() public view returns (address) {
    return _walletN;
}

/**
 * @return the Negativ _wallet.
 */