contract TeamTokensHolder is Owned{
    using SafeMath for uint256;

    LifeBankerCoin public LBC;
    uint256 public startTime;
    uint256 public duration = 6 * 30 * 24 * 3600; //six months

    uint256 public total = 2250000000000000000000000000;  // 2.25 billion  22.5% 
    uint256 public amountPerRelease = total.div(6);       // 375 million
    uint256 public collectedTokens;

    address public TeamAddress = 0x7572b353B176Cc8ceF510616D0fDF8B4551Ba16e;

    event TokensWithdrawn(address indexed _holder, uint256 _amount);
    event ClaimedTokens(address indexed _token, address indexed _controller, uint256 _amount);


    constructor(address _owner, address _lbc) public{
        owner = _owner;
        LBC = LifeBankerCoin(_lbc);
        startTime = now;
    }

    /*
     * @dev The Dev (Owner) will call this method to extract the tokens
     */
    function unLock() public onlyOwner returns(bool){
        uint256 balance = LBC.balanceOf(address(this));

        //  amountPerRelease * [(now - startTime) / duration]
        uint256 canExtract = amountPerRelease.mul((getTime().sub(startTime)).div(duration));

        uint256 amount = canExtract.sub(collectedTokens);

        if (amount == 0){
            revert();
        } 

        if (amount > balance) {
            amount = balance;
        }

        assert (LBC.transfer(TeamAddress, amount));
        emit TokensWithdrawn(TeamAddress, amount);
        collectedTokens = collectedTokens.add(amount);
        
        return true;
    }

    /* Get the timestamp of the current block */
    function getTime() view public returns(uint256){
        return now;
    }

    /// Safe Function
    /// @dev This method can be used by the controller to extract mistakenly
    /// @param _token The address of the token contract that you want to recover
    function claimTokens(address _token) public onlyOwner returns(bool){
        require(_token != address(LBC));

        ERC20 token = ERC20(_token);
        uint256 balance = token.balanceOf(this);
        token.transfer(owner, balance);
        emit ClaimedTokens(_token, owner, balance);
        return true;
    }
}
/* @title This contract locks the tokens of the team and early investors.
 * @notice The tokens are locked for a total of three years, unlocking one-sixth every six months.
 * Unlockable Amount(%)
 *    ^
 * 100|---------------------------- * * *
 *    |                           / :  
 *    |----------------------- *    :  
 *    |                      / :    :  
 *    |------------------ *    :    :  
 *    |                 / :    :    :  
 *  50|------------- *    :    :    :  
 *    |            / :    :    :    :  
 *    |-------- *    :    :    :    :  
 *    |       / :    :    :    :    :  
 *    |--- *    :    :    :    :    :  
 *    |  / :    :    :    :    :    :  
 *    +----*----*----*----*----*----*-->
 *    0   0.5   1   1.5   2   2.5   3   Time(year)
 *
 */
function claimTokens(address _token) public onlyOwner returns(bool){
    require(_token != address(LBC));

    ERC20 token = ERC20(_token);
    uint256 balance = token.balanceOf(this);
    token.transfer(owner, balance);
    emit ClaimedTokens(_token, owner, balance);
    return true;
}

/// Safe Function
/// @dev This method can be used by the controller to extract mistakenly
/// @param _token The address of the token contract that you want to recover