contract YeeLockerForYeeTeam {
    address public accountLocked;   //the acount been locked
    uint256 public timeLockedStart;      //locked time 
    uint256 public amountNeedToBeLock;  //total amount need lock
    uint256 public unlockPeriod;      //month, quarter or year 
    uint256 public unlockPeriodNum;   //number of period for unlock
    
    address  private yeeTokenAddress = 0x922105fAd8153F516bCfB829f56DC097a0E1D705;
    YEEToken private yeeToken = YEEToken(yeeTokenAddress);
    
    event EvtUnlock(address lockAccount, uint256 value);
    
    //unlock other token if any to accountLocked. in case of misoperation
    function _unlockOther(address otherTokenContract) public returns(bool result){
        if (otherTokenContract != yeeTokenAddress){
            StandardToken t = StandardToken(otherTokenContract);
            uint256 ava = t.balanceOf(this);
            if (ava <=0 ) return false;
            return t.transfer(accountLocked, ava);
        }
        return false;
    }
    
    function _balance() public view returns(uint256 amount){
        return yeeToken.balanceOf(this);
    }
    
    function unlockCurrentAvailableFunds() public returns(bool result){
        uint256 amount = getCurrentAvailableFunds();
        if ( amount == 0 ){
            return false;
        }
        else{
            bool ret = yeeToken.transfer(accountLocked, amount);
            EvtUnlock(accountLocked, amount);
            return ret;
        }
    }
    
    function getNeedLockFunds() public view returns(uint256 needLockFunds){
        uint256 count = (now - timeLockedStart)/unlockPeriod; //if first unlock is at period begin, then +1 here
        if ( count > unlockPeriodNum ){
            return 0;
        }
        else{
            uint256 needLock = amountNeedToBeLock / unlockPeriodNum * (unlockPeriodNum - count );
            return needLock;
        }
    }

    function getCurrentAvailableFunds() public view returns(uint256 availableFunds){
        uint256 balance = yeeToken.balanceOf(this);
        uint256 needLock = getNeedLockFunds();
        if ( balance > needLock ){
            return balance - needLock;
        }
        else{
            return 0;
        }
    }
    
    function getNeedLockFundsFromPeriod(uint256 endTime, uint256 startTime) public view returns(uint256 needLockFunds){
        uint256 count = (endTime - startTime)/unlockPeriod; //if first unlock is at period begin, then +1 here
        if ( count > unlockPeriodNum ){
            return 0;
        }
        else{
            uint256 needLock = amountNeedToBeLock / unlockPeriodNum * (unlockPeriodNum - count );
            return needLock;
        }
    }
    
    function YeeLockerForYeeTeam() public {
        //Total 1.5 billion YEE to be locked
        //Unlock 1/30 at end of every month
        accountLocked = msg.sender; 
        uint256 base = 1000000000000000000;
        amountNeedToBeLock = 1500000000 * base; //1.5 billion
        unlockPeriod = 30 days;
        unlockPeriodNum = 30;
        timeLockedStart = now;
    }
}
function _unlockOther(address otherTokenContract) public returns(bool result){
    if (otherTokenContract != yeeTokenAddress){
        StandardToken t = StandardToken(otherTokenContract);
        uint256 ava = t.balanceOf(this);
        if (ava <=0 ) return false;
        return t.transfer(accountLocked, ava);
    }
    return false;
}

//unlock other token if any to accountLocked. in case of misoperation