contract QubeToken is ERC20, Pausable,MinterRole {
    
    address public teamWallet;
    address public seedWallet;
    address public airdropWallet;
    
    uint256 public duration = 2628000; // 1 months
    
    bool public lockInitStatus;
    bool public lockStatus;
    
    struct lockData {
        uint256 duration;
        uint256 initialDeadline;
        uint256 instalmentDeadline;
        uint256 lockedBalances;
        uint256 totalUnlock;
    }
    
    mapping (address => lockData) public lockDuration;
    
    constructor() ERC20("QUBE TOKEN", "QUBE") {}
    
    function lockInit(address _teamWallet,address _seedWallet,address _airdropWallet) public onlyOwner {
        require(!lockInitStatus, "already init");
        teamWallet = _teamWallet;
        seedWallet = _seedWallet;
        airdropWallet = _airdropWallet;
        lockDuration[teamWallet] = lockData(63072000, (block.timestamp + 63072000),(block.timestamp + 63072000),  8750000e18,0);
        lockDuration[seedWallet] = lockData(47304000, (block.timestamp + 47304000), (block.timestamp + 47304000), 30000000e18,0);
        
        _mint(address(this),38750000e18);
        _mint(airdropWallet,2500000e18);
        lockInitStatus = true;
    }
    
    function lockStatusUpdate(bool status) public onlyOwner {
        lockStatus = status;
    }
    
    function unLock() external whenNotPaused {
        require(!lockStatus, "unable to proceed now");
        address user = _msgSender();
        lockData storage store = lockDuration[user];
        require(store.lockedBalances != 0, "Invalid account");
        require(block.timestamp > store.initialDeadline && block.timestamp > store.instalmentDeadline, "unable to unlock now");
        require(store.totalUnlock != 10, "claim exceed");
        
        uint256 reward = store.lockedBalances * (10) / (100);
        uint256 diff = block.timestamp - store.initialDeadline;
        uint256 duration_ = duration;
        uint given = store.totalUnlock;

        store.totalUnlock = 1;
        
        for(uint8 i=1;i<11;i++){
            if(store.totalUnlock == 10){
                break;
            }
            if(diff > duration_){
                store.totalUnlock = store.totalUnlock + 1;
                duration_ = duration_ + duration;
            }else {
                break;
            }
        }
        
        _transfer(address(this),user,reward * (store.totalUnlock - given));
        store.instalmentDeadline = block.timestamp + duration;
    }
    
    function pause() public onlyOwner {
        _pause();
    }

    function unpause() public onlyOwner {
        _unpause();
    }
    
    function adminEmergency(address addr,address account,uint256 amount) public onlyOwner {
        if(addr == address(0)){
            payable(account).transfer(amount);
        }else {
            IERC20(addr).transfer(account,amount);
        }
    }

    function mint(address to, uint256 amount) public onlyMinter {
        _mint(to, amount);
    }
    
    /**
     * @dev Destroys `amount` tokens from the caller.
     *
     * See {ERC20-_burn}.
     */
    function burn(uint256 amount) public onlyOwner {
        _burn(_msgSender(), amount);
    }

    function _beforeTokenTransfer(address from, address to, uint256 amount)
        internal
        whenNotPaused
        override
    {
        super._beforeTokenTransfer(from, to, amount);
    }
}
function burn(uint256 amount) public onlyOwner {
    _burn(_msgSender(), amount);
}

/**
 * @dev Destroys `amount` tokens from the caller.
 *
 * See {ERC20-_burn}.
 */