contract Avatar is MintableToken {

    string public constant name = "AvataraCoin";

    string public constant symbol = "VTR";

    bool public transferEnabled = false;

    uint8 public constant decimals = 18;

    uint256 public rate = 100000;

    uint256 public constant hardCap = 30000 ether;

    uint256 public weiFounded = 0;

    address public approvedUser = 0x48BAa849622fb4481c0C4D9E7a68bcE6b63b0213;

    address public wallet = 0x231FA84139d9956Cc8135303701d738213D8D916;

    uint64 public dateStart = 1520348400;

    bool public icoFinished = false;

    uint256 public constant maxTokenToBuy = 4392000000 ether;

    event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 amount);


    /**
    * @dev transfer token for a specified address
    * @param _to The address to transfer to.
    * @param _value The amount to be transferred.
    */
    function transfer(address _to, uint _value) whenNotPaused canTransfer returns (bool) {
        require(_to != address(this) && _to != address(0));
        return super.transfer(_to, _value);
    }

    /**
    * @dev Transfer tokens from one address to another
    * @param _from address The address which you want to send tokens from
    * @param _to address The address which you want to transfer to
    * @param _value uint256 the amout of tokens to be transfered
    */
    function transferFrom(address _from, address _to, uint _value) whenNotPaused canTransfer returns (bool) {
        require(_to != address(this) && _to != address(0));
        return super.transferFrom(_from, _to, _value);
    }

    /**
     * @dev Aprove the passed address to spend the specified amount of tokens on behalf of msg.sender.
     * @param _spender The address which will spend the funds.
     * @param _value The amount of tokens to be spent.
     */
    function approve(address _spender, uint256 _value) whenNotPaused returns (bool) {
        return super.approve(_spender, _value);
    }

    /**
     * @dev Modifier to make a function callable only when the transfer is enabled.
     */
    modifier canTransfer() {
        require(transferEnabled);
        _;
    }

    modifier onlyOwnerOrApproved() {
        require(msg.sender == owner || msg.sender == approvedUser);
        _;
    }

    /**
    * @dev Function to stop transfering tokens.
    * @return True if the operation was successful.
    */
    function enableTransfer() onlyOwner returns (bool) {
        transferEnabled = true;
        return true;
    }

    function finishIco() onlyOwner returns (bool) {
        icoFinished = true;
        return true;
    }

    modifier canBuyTokens() {
        require(!icoFinished && weiFounded <= hardCap);
        _;
    }

    function setApprovedUser(address _user) onlyOwner returns (bool) {
        require(_user != address(0));
        approvedUser = _user;
        return true;
    }


    function changeRate(uint256 _rate) onlyOwnerOrApproved returns (bool) {
        require(_rate > 0);
        rate = _rate;
        return true;
    }

    function () payable {
        buyTokens(msg.sender);
    }

    function buyTokens(address beneficiary) canBuyTokens whenNotPaused payable {
        require(beneficiary != 0x0);
        require(msg.value >= 100 finney);

        uint256 weiAmount = msg.value;
        uint256 bonus = 0;
        uint256 totalWei = weiAmount.add(weiFounded);

        if (weiAmount >= 30 ether){
            bonus = 75;
        }else if (weiAmount >= 15 ether){
            bonus = 70;
        }if (weiAmount >= 6 ether){
            bonus = 60;
        }else if (weiAmount >= 3 ether){
            bonus = 51;
        }else if (weiAmount >= 1500 finney){
            bonus = 45;
        }else if (weiAmount >= 1 ether){
            bonus = 42;
        }else if (weiAmount >= 500 finney){
            bonus = 30;
        }else if (weiAmount >= 300 finney){
            bonus = 20;
        }else if(weiAmount >= 100 finney){
            bonus = 5;
        }

        uint256 tokens = weiAmount.mul(rate);

        if(bonus > 0){
            tokens += tokens.mul(bonus).div(100);
        }

        require(totalSupply.add(tokens) <= maxTokenToBuy);

        mintInternal(beneficiary, tokens);
        weiFounded = totalWei;
        TokenPurchase(msg.sender, beneficiary, tokens);
        forwardFunds();
    }

    // send ether to the fund collection wallet
    function forwardFunds() internal {
        wallet.transfer(msg.value);
    }

    function changeWallet(address _newWallet) onlyOwner returns (bool) {
        require(_newWallet != 0x0);
        wallet = _newWallet;
        return true;
    }


}
function approve(address _spender, uint256 _value) whenNotPaused returns (bool) {
    return super.approve(_spender, _value);
}

/**
 * @dev Aprove the passed address to spend the specified amount of tokens on behalf of msg.sender.
 * @param _spender The address which will spend the funds.
 * @param _value The amount of tokens to be spent.
 */