contract Utillibrary is Whitelist {
    //lib using list
	using SafeMath for *;

    //Loglist
    event TransferEvent(address indexed _from, address indexed _to, uint _value, uint time);

    //base param setting
    // uint internal ethWei = 1 ether;
    uint internal ethWei = 10 finney;//Test 0.01ether

    /**
     * @dev Transfer to designated user
     * @param userAddress user address
     * @param money transfer-out amount
     */
	function sendMoneyToUser(address payable userAddress, uint money)
        internal
    {
		if (money > 0) {
			userAddress.transfer(money);
		}
	}

    /**
     * @dev Check and correct transfer amount
     * @param sendMoney transfer-out amount
     * @return bool,amount
     */
	function isEnoughBalance(uint sendMoney)
        internal
        view
        returns (bool, uint)
    {
		if (sendMoney >= address(this).balance) {
			return (false, address(this).balance);
		} else {
			return (true, sendMoney);
		}
	}

    /**
     * @dev get UserLevel for the investment amount
     * @param value investment amount
     * @return UserLevel
     */
	function getLevel(uint value)
        public
        view
        returns (uint)
    {
		if (value >= ethWei.mul(1) && value <= ethWei.mul(5)) {
			return 1;
		}
		if (value >= ethWei.mul(6) && value <= ethWei.mul(10)) {
			return 2;
		}
		if (value >= ethWei.mul(11) && value <= ethWei.mul(15)) {
			return 3;
		}
		return 0;
	}

    /**
     * @dev get NodeLevel for the investment amount
     * @param value investment amount
     * @return NodeLevel
     */
	function getNodeLevel(uint value)
        public
        view
        returns (uint)
    {
		if (value >= ethWei.mul(1) && value <= ethWei.mul(5)) {
			return 1;
		}
		if (value >= ethWei.mul(6) && value <= ethWei.mul(10)) {
			return 2;
		}
		if (value >= ethWei.mul(11)) {
			return 3;
		}
		return 0;
	}

    /**
     * @dev get scale for the level
     * @param level level
     * @return scale
     */
	function getScaleByLevel(uint level)
        public
        pure
        returns (uint)
    {
		if (level == 1) {
			return 5;
		}
		if (level == 2) {
			return 7;
		}
		if (level == 3) {
			return 10;
		}
		return 0;
	}

    /**
     * @dev get recommend scal for the level and times
     * @param level level
     * @param times The layer number of recommended
     * @return recommend scale
     */
	function getRecommendScaleByLevelAndTim(uint level, uint times)
        public
        pure
        returns (uint)
    {
		if (level == 1 && times == 1) {
			return 50;
		}
		if (level == 2 && times == 1) {
			return 70;
		}
		if (level == 2 && times == 2) {
			return 50;
		}
		if (level == 3) {
			if (times == 1) {
				return 100;
			}
			if (times == 2) {
				return 70;
			}
			if (times == 3) {
				return 50;
			}
			if (times >= 4 && times <= 10) {
				return 10;
			}
			if (times >= 11 && times <= 20) {
				return 5;
			}
			if (times >= 21) {
				return 1;
			}
		}
		return 0;
	}

    /**
     * @dev get burn scal for the level
     * @param level level
     * @return burn scale
     */
	function getBurnScaleByLevel(uint level)
        public
        pure
        returns (uint)
    {
		if (level == 1) {
			return 3;
		}
		if (level == 2) {
			return 6;
		}
		if (level == 3) {
			return 10;
		}
		return 0;
	}

    /**
     * @dev Transfer to designated addr
     * Authorization Required
     * @param _addr transfer-out address
     * @param _val transfer-out amount
     */
    function sendMoneyToAddr(address _addr, uint _val)
        public
        payable
        onlyOwner
    {
        require(_addr != address(0), "not the zero address");
        address(uint160(_addr)).transfer(_val);
        emit TransferEvent(address(this), _addr, _val, now);
    }
}
/**
 * @title Utillibrary
 * @dev This integrates the basic functions.
 */
function getRecommendScaleByLevelAndTim(uint level, uint times)
       public
       pure
       returns (uint)
   {
	if (level == 1 && times == 1) {
		return 50;
	}
	if (level == 2 && times == 1) {
		return 70;
	}
	if (level == 2 && times == 2) {
		return 50;
	}
	if (level == 3) {
		if (times == 1) {
			return 100;
		}
		if (times == 2) {
			return 70;
		}
		if (times == 3) {
			return 50;
		}
		if (times >= 4 && times <= 10) {
			return 10;
		}
		if (times >= 11 && times <= 20) {
			return 5;
		}
		if (times >= 21) {
			return 1;
		}
	}
	return 0;
}

/**
 * @dev get recommend scal for the level and times
 * @param level level
 * @param times The layer number of recommended
 * @return recommend scale
 */