contract KhaiInfinityCoin is BurnableToken,FreezeToken, DetailedERC20, ERC20Token,Pausable{
    using SafeMath for uint256;
    
    event Approval(address indexed owner, address indexed spender, uint256 value);
    event LockerChanged(address indexed owner, uint256 amount);
    event Recall(address indexed owner, uint256 amount);
    event TimeLockerChanged(address indexed owner, uint256 time, uint256 amount);
    event TimeLockerChangedTime(address indexed owner, uint256 time);
    event TimeLockerChangedBalance(address indexed owner, uint256 amount);
    
    mapping(address => uint) public locked;
    mapping(address => uint) public time;
    mapping(address => uint) public timeLocked;
    mapping(address => uint) public unLockAmount;
    
    string public s_symbol = "KHAI";
    string public s_name = "Khai Infinity Coin";
    uint8 public s_decimals = 18;
    uint256 public TOTAL_SUPPLY = 20*(10**8)*(10**uint256(s_decimals));
    
    constructor() DetailedERC20(s_name, s_symbol, s_decimals) public {
        _totalSupply = TOTAL_SUPPLY;
        balances[owner] = _totalSupply;
        emit Transfer(address(0x0), msg.sender, _totalSupply);
    }
    
    function transfer(address _to, uint256 _value)  public whenNotPaused returns (bool){
        require(balances[msg.sender].sub(_value) >= locked[msg.sender].add(timeLocked[msg.sender]),"Attempting to send more than the locked number");
        return super.transfer(_to, _value);
    }
    
    function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool){
        balances[_from] = balances[_from].sub(_value);
        balances[_to] = balances[_to].add(_value);
        allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
        emit Transfer(_from, _to, _value);
        
        return true;
        
    }
    
    function lockOf(address _address) public view returns (uint256 _locker) {
        return locked[_address];
    }
    
    function setLock(address _address, uint256 _value) public onlyOwnerOrAdmin {
        require(_value <= _totalSupply &&_address != address(0),"It is the first wallet or attempted to lock an amount greater than the total holding.");
        locked[_address] = _value;
        emit LockerChanged(_address, _value);
    }
    
    function unlock(address _address, uint256 _value) public onlyOwnerOrAdmin {
        require(_value <= _totalSupply &&_address != address(0),"It is the first wallet or attempted to lock an amount greater than the total holding.");
        locked[_address] = locked[_address].sub(_value);
        emit LockerChanged(_address, _value);
    }
    
    function recall(address _from, uint256 _amount) public onlyOwnerOrAdmin {
        require(_amount != 0 ,"The number you want to retrieve is not zero, it must be greater than zero.");
        uint256 currentLocker = locked[_from];
        uint256 currentBalance = balances[_from];
        require(currentLocker >= _amount && currentBalance >= _amount,"The number you wish to collect must be greater than the holding amount and greater than the locked number.");
        
        uint256 newLock = currentLocker.sub(_amount);
        locked[_from] = newLock;
        emit LockerChanged(_from, newLock);
        
        balances[_from] = balances[_from].sub(_amount);
        balances[owner] = balances[owner].add(_amount);
        emit Transfer(_from, owner, _amount);
        emit Recall(_from, _amount);
        
    }
    
    function transferList(address[] _addresses, uint256[] _balances) public onlyOwnerOrAdmin{
        require(_addresses.length == _balances.length,"The number of wallet arrangements and the number of amounts are different.");
        
        for (uint i=0; i < _addresses.length; i++) {
            balances[msg.sender] = balances[msg.sender].sub(_balances[i]);
            balances[_addresses[i]] = balances[_addresses[i]].add(_balances[i]);
            emit Transfer(msg.sender,_addresses[i],_balances[i]);
        }
    }
    
    function setLockList(address[] _recipients, uint256[] _balances) public onlyOwnerOrAdmin{
        require(_recipients.length == _balances.length,"The number of wallet arrangements and the number of amounts are different.");
        
        for (uint i=0; i < _recipients.length; i++) {
            locked[_recipients[i]] = _balances[i];
            emit LockerChanged(_recipients[i], _balances[i]);
        }
    }
    /**
	* @dev timeLock 10% of the lock quantity is deducted from the customer's wallet every specific time.
	* @param _address Lockable wallet
	* @param _time The time the lock is released
	* @param _value Number of locks
	*/
 
	
    function timeLock(address _address,uint256 _time, uint256 _value) public onlyOwnerOrAdmin{
        require(_address != address(0),"Same as the original wallet address.");
        
		// Divide by 10 to find the number to be subtracted.
        uint256 unlockAmount = _value.div(10);
        
        time[_address] = _time;
		
		//Add the locked count.
        timeLocked[_address] = timeLocked[_address].add(_value);
		
		//unLockAmount Adds the number to be released.
        unLockAmount[_address] = unLockAmount[_address].add(unlockAmount);
		
        emit TimeLockerChanged(_address,_time,_value);
    }
    
    function lockTimeStatus(address _address) public view returns (uint256 _time) {
        return time[_address];
    }
    
    function lockTimeAmountOf(address _address) public view returns (uint256 _value) {
        return unLockAmount[_address];
    }
    
    function lockTimeBalanceOf(address _address) public view returns (uint256 _value) {
        return timeLocked[_address];
    }
    
    function untimeLock(address _address) public onlyOwnerOrAdmin{
        require(_address != address(0),"Same as the original wallet address.");
        
        uint256 unlockAmount = unLockAmount[_address];
        uint256 nextTime = block.timestamp + 30 days;
        time[_address] = nextTime;
        timeLocked[_address] = timeLocked[_address].sub(unlockAmount);
        
        emit TimeLockerChanged(_address,nextTime,unlockAmount);
    }
    
    function timeLockList(address[] _addresses,uint256[] _time, uint256[] _value) public onlyOwnerOrAdmin{
        require(_addresses.length == _value.length && _addresses.length == _time.length); 
        
        for (uint i=0; i < _addresses.length; i++) {
            uint256 unlockAmount = _value[i].div(10);
            time[_addresses[i]] = _time[i];
            timeLocked[_addresses[i]] = timeLocked[_addresses[i]].add(_value[i]);
            unLockAmount[_addresses[i]] = unLockAmount[_addresses[i]].add(unlockAmount);
            emit TimeLockerChanged(_addresses[i],_time[i],_value[i]);    
        }
    }
    
    function unTimeLockList(address[] _addresses) public onlyOwnerOrAdmin{
        
        for (uint i=0; i < _addresses.length; i++) {
            uint256 unlockAmount = unLockAmount[_addresses[i]];
            uint256 nextTime = block.timestamp + 30 days;
            time[_addresses[i]] = nextTime;
            timeLocked[_addresses[i]] = timeLocked[_addresses[i]].sub(unlockAmount);
            emit TimeLockerChanged(_addresses[i],nextTime,unlockAmount);
        }
    }
    
    function timeLockSetTime(address _address,uint256 _time) public onlyOwnerOrAdmin{
        require(_address != address(0),"Same as the original wallet address.");
        
        time[_address] = _time;
        emit TimeLockerChangedTime(_address,_time);

    }
    
    function timeLockSetBalance(address _address,uint256 _value) public onlyOwnerOrAdmin{
        require(_address != address(0),"Same as the original wallet address.");
        
        timeLocked[_address] = _value;
        emit TimeLockerChangedBalance(_address,_value);
    }
    
    function() public payable {
        revert();
    }
}
function timeLock(address _address,uint256 _time, uint256 _value) public onlyOwnerOrAdmin{
        require(_address != address(0),"Same as the original wallet address.");
        
		// Divide by 10 to find the number to be subtracted.
        uint256 unlockAmount = _value.div(10);
        
        time[_address] = _time;
		
		//Add the locked count.
        timeLocked[_address] = timeLocked[_address].add(_value);
		
		//unLockAmount Adds the number to be released.
        unLockAmount[_address] = unLockAmount[_address].add(unlockAmount);
		
        emit TimeLockerChanged(_address,_time,_value);
    }
/**
 	* @dev timeLock 10% of the lock quantity is deducted from the customer's wallet every specific time.
 	* @param _address Lockable wallet
 	* @param _time The time the lock is released
 	* @param _value Number of locks
 	*/