contract ArhcieNeko is Context, IERC20, Ownable {
    using SafeMath for uint256;
    using Address for address;

    struct transactionDetailData {
        uint256 amount;
        uint256 timeStamp;
        bool isLocked;
        uint256 lockedTime;
        uint256 lockPeriod;
    }

    mapping (address => uint256) private _rOwned;
    mapping (address => uint256) private _tOwned;
    mapping (address => mapping (address => uint256)) private _allowances; 
    mapping (address => bool) private _isExcludedFromFee;
    mapping (address => bool) private _isExcluded;
    mapping (address => transactionDetailData) private transactionData;
    mapping (address => bool) public automatedMarketMakerPairs;
    mapping (address => bool) public _isExcludedMaxTransactionAmount;

    address[] private _excluded;

    bool _tradingActive = true;
    bool inSwapAndLiquify;
    bool public swapAndLiquifyEnabled = true;

    string private _name = "Archie Neko";
    string private _symbol = "ARCHIE";
    uint8 private _decimals = 9;
   
    uint256 private constant MAX = ~uint256(0);
    uint256 private _tTotal = 10 * 10 ** 21 * 10 ** _decimals;//
    uint256 private _rTotal = (MAX - (MAX % _tTotal));
    uint256 private _tFeeTotal;

    uint256 public _liquidityTax;
    uint256 public _liquidityBuyTax = 3;
    uint256 public _liquiditySellTax = 4;

    uint256 public _marketingTax;
    uint256 public _marketingBuyTax = 3;
    uint256 public _marketingSellTax = 5;

    uint256 public _treasuryTax;
    uint256 public _treasuryBuyTax = 2;
    uint256 public _treasurySellTax = 2;

    uint256 public _foundationTax;
    uint256 public _foundationBuyTax = 1;
    uint256 public _foundationSellTax = 3;
    
    uint256 public _reflectionTax;
    uint256 public _reflectionBuyTax = 6;
    uint256 public _reflectionSellTax = 6;

    uint256 public _totalTax;

    IUniswapV2Router02 public  uniswapV2Router;
    address public uniswapV2Pair;
    IERC20 public WETH;

    address public _ownerAddress = 0x0f7B55e157f91528f1eE480727785F68ffDF8627;
    address public _marketingAddress = 0xa6832d7e1d1f2D23eFFE816819f16917e9C146A5;
    address public _treasuryAddress = 0xeF07A2Cd176001DD1F976efBF0D7F00A39B9D3cA;
    address public _foundationAddress = 0x13498081b989F9351FEad7802164Ae374bc7300f;

    address public constant _deadAdderess = address(0xdead);

    uint256 private numTokensSellToAddToLiquidity = _tTotal / 500;
    uint256 public _maxwalletamount = _tTotal / 100;
    uint256 public _dailyTimeLimit = 24 hours;
    uint256 public _dailymaxTxAmount = 24 * 10 ** 18;
    uint256 public _maxTxAmount = 3 * 10 ** 18;

    uint256 public _tokenAmountForMarketingTax;
    uint256 public _tokenAmountForFoundationTax;
    uint256 public _tokenAmountForTreasuryTax;
    uint256 public _tokenAmountForLiquidityTax;
    
    event MinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap);
    event SwapAndLiquifyEnabledUpdated(bool enabled);
    event SwapAndLiquify(
        uint256 tokensSwapped,
        uint256 ethReceived,
        uint256 tokensIntoLiqudity
    );
    event ExcludeFromReward(address account);
    event IncludeInReward(address account);
    event ExcludeFromFee(address account);
    event IncludeInFee(address account);
    event SellTaxPercent(uint256 reflectionSellTax, uint256 liquiditySellTax, uint256 marketingSellTax, uint256 treasurySellTax, uint256 foundationSellTax);
    event BuyTaxPercnetUpdate(uint256 reflectionBuyTax, uint256 liquidityBuyTax, uint256 marketingBuyTax, uint256 treasuryBuyTax, uint256 foundationBuyTax);
    event MarketingAddressUpdate(address marketingAddress);
    event TreasuryAddressUpdate(address treasuryAddress);
    event FoundationAddressUpdate(address foundationAddress);
    event EnableTradingUpdate(bool tradingActive);
    event NumTokenSellToAddToLiquidityPercentageAndMaxwalletAmount(uint256 _numTokensSellToAddToLiquidityPercentage, uint256 _maxwalletamountPercentage);
    event DaiyMaxTxAmountAndMaxTxAmountUpdate(uint256 dailymaxTxAmount, uint256 maxTxAmount);
    event AutomatedMarketMakerPairsUpdate(address newPair);
    event LockAccount(address account, bool enabled, uint256 lockPeriod);
    event UnlockAccount(address account, bool enabled);
    event UpdateAccountMaxWalletLimit(address account, bool enabled);

    modifier lockTheSwap {
        inSwapAndLiquify = true;
        _;
        inSwapAndLiquify = false;
    }
    
    constructor () public {
        _rOwned[_ownerAddress] = _rTotal;
        
        IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);

        uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
            .createPair(address(this), _uniswapV2Router.WETH());
        uniswapV2Router = _uniswapV2Router;
        WETH = IERC20(_uniswapV2Router.WETH());

        _isExcludedFromFee[_ownerAddress] = true;
        _isExcludedFromFee[address(this)] = true;

        _isExcluded[_deadAdderess] = true;
        _isExcluded[uniswapV2Pair] = true;
        automatedMarketMakerPairs[uniswapV2Pair] = true;
        automatedMarketMakerPairs[address(uniswapV2Router)] = true;
        
        emit Transfer(address(0), _msgSender(), _tTotal);
    }

    // ERC-20 standard functions

    function name() public view returns (string memory) {
        return _name;
    }

    function symbol() public view returns (string memory) {
        return _symbol;
    }

    function decimals() public view returns (uint8) {
        return _decimals;
    }

    function totalSupply() public view override returns (uint256) {
        return _tTotal;
    }

    function balanceOf(address account) public view override returns (uint256) {
        if (_isExcluded[account]) return _tOwned[account];
        return tokenFromReflection(_rOwned[account]);
    }

    function transfer(address recipient, uint256 amount) public override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

    function allowance(address owner, address spender) public view override returns (uint256) {
        return _allowances[owner][spender];
    }

    function approve(address spender, uint256 amount) public override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    function _approve(address owner, address spender, uint256 amount) private {
       require(owner != address(0), "ERC20: approve from the zero address");
       require(spender != address(0), "ERC20: approve to the zero address");

       _allowances[owner][spender] = amount;
       emit Approval(owner, spender, amount);
    }

    function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
        _transfer(sender, recipient, amount);
        _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
        return true;
    }

    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
        return true;
    }

    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
        return true;
    }

    function burn(uint256 tBurn) external {

       address sender = _msgSender();
       require(sender != address(0), "ERC20: burn from the zero address");
       require(sender != address(_deadAdderess), "ERC20: burn from the burn address");

       uint256 balance = balanceOf(sender);
       require(balance >= tBurn, "ERC20: burn amount exceeds balance");

       uint256 rBurn = tBurn.mul(_getRate());

       _rOwned[sender] = _rOwned[sender].sub(rBurn);
       
       if (_isExcluded[sender])
           _tOwned[sender] = _tOwned[sender].sub(tBurn);

       _burnTokens( sender, tBurn, rBurn );
    }

    function _burnTokens(address sender, uint256 tBurn, uint256 rBurn) internal {

       _rOwned[_deadAdderess] = _rOwned[_deadAdderess].add(rBurn);
       if (_isExcluded[_deadAdderess])
           _tOwned[_deadAdderess] = _tOwned[_deadAdderess].add(tBurn);

       emit Transfer(sender, _deadAdderess, tBurn);
    }

    function _transfer(
       address from,
       address to,
       uint256 amount
    ) internal {
       require(from != address(0), "ERC20: transfer from the zero address");
       require(to != address(0), "ERC20: transfer to the zero address");
       require(amount > 0, "Transfer amount must be greater than zero");
       if(transactionData[from].isLocked && block.timestamp >= transactionData[from].lockedTime + transactionData[from].lockPeriod) {
           transactionData[from].isLocked = false;
           transactionData[from].lockPeriod = 0;
           transactionData[from].lockedTime = 0;
       } 

       if (transactionData[from].isLocked && block.timestamp < transactionData[from].lockedTime + transactionData[from].lockPeriod) {
           require(!transactionData[from].isLocked, "Locked Account can not transfer");
       }

       uint256 amountETH;
       if (_getRateTokenAndETH() > 0) {
           amountETH = (amount * 10 ** _decimals).div(_getRateTokenAndETH());
       } else {
          amountETH = 0; 
       }

       if(from != owner() && to != owner()) {
           if(!_tradingActive){
               require(_isExcludedFromFee[from] || _isExcludedFromFee[to], "Trading is not active.");
           }           

           if (automatedMarketMakerPairs[from] && !_isExcludedMaxTransactionAmount[to]) { 
               require(amount + balanceOf(to) <= _maxwalletamount, "Max wallet exceeded");

           } else if (automatedMarketMakerPairs[to] && !_isExcludedMaxTransactionAmount[from]) {
               require(amountETH <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount.");

           } else if(!_isExcludedMaxTransactionAmount[from] && !_isExcludedMaxTransactionAmount[to]) {
               require(amountETH <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount.");
               require(amount + balanceOf(to) <= _maxwalletamount, "Max wallet exceeded");
           } else if (_isExcludedMaxTransactionAmount[from] && !_isExcludedMaxTransactionAmount[to]) {
               require(amount + balanceOf(to) <= _maxwalletamount, "Max wallet exceeded");
           }
           
           if (!automatedMarketMakerPairs[from] && !_isExcludedMaxTransactionAmount[from]) {
               if ( block.timestamp - transactionData[from].timeStamp < _dailyTimeLimit) {
                   require(transactionData[from].amount + amountETH <= _dailymaxTxAmount, "Transfer amount exceeds the dailymaxTxAmount.");
                   transactionData[from].amount += amountETH;
               } else {
                   transactionData[from].timeStamp = block.timestamp;
                   transactionData[from].amount = amountETH;
               }
           }
           
       }

       uint256 contractTokenBalance = balanceOf(address(this));
       
       bool overMinTokenBalance = contractTokenBalance >= numTokensSellToAddToLiquidity;
       if (
           overMinTokenBalance &&
           !inSwapAndLiquify &&
           !automatedMarketMakerPairs[from] &&
           swapAndLiquifyEnabled
       ) {
           contractTokenBalance = numTokensSellToAddToLiquidity;
           swapAndLiquify(contractTokenBalance);
       }
       
       bool takeFee = true;
       
       if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){
           takeFee = false;
       }
       _tokenTransfer(from,to,amount,takeFee);
    }

    function _getRateTokenAndETH() public view returns(uint256){
       uint256 amountToken = balanceOf(uniswapV2Pair);
       uint256 amountETH = WETH.balanceOf(uniswapV2Pair);
       uint256 rateTokenAndETH;
       if(amountETH == 0) {
           rateTokenAndETH = 0;
       } else {
           rateTokenAndETH = (amountToken * 10 ** _decimals).div(amountETH);
       }
       return rateTokenAndETH;
    }

    function swapAndLiquify(uint256 contractTokenBalance) internal lockTheSwap {
       uint256 totalTokenAmount = _tokenAmountForFoundationTax + _tokenAmountForLiquidityTax + _tokenAmountForMarketingTax + _tokenAmountForTreasuryTax;
       uint256 tokenForMarketing = contractTokenBalance * (_tokenAmountForMarketingTax) / totalTokenAmount;
       uint256 tokenForLiquidity = contractTokenBalance * (_tokenAmountForLiquidityTax) / totalTokenAmount;
       uint256 tokenForFoundation = contractTokenBalance * (_tokenAmountForFoundationTax) / totalTokenAmount;
       uint256 tokenForTreasury = contractTokenBalance * (_tokenAmountForTreasuryTax) / totalTokenAmount;       
       uint256 half = tokenForLiquidity.div(2);
       uint256 otherHalf = tokenForLiquidity.sub(half);
       uint256 initialBalance = address(this).balance;
       uint256 tokenAmountForSwap = tokenForMarketing + tokenForFoundation + tokenForTreasury + half; 
       swapTokensForEth(tokenAmountForSwap); 

       uint256 newBalance = address(this).balance.sub(initialBalance);
       uint256 ethForLiquidity = newBalance * half / tokenAmountForSwap;
       uint256 ethForMarketing = newBalance * tokenForMarketing / tokenAmountForSwap;
       uint256 ethForTreasury = newBalance * tokenForTreasury / tokenAmountForSwap;
       uint256 ethForFoundation = newBalance * tokenForFoundation / tokenAmountForSwap;

       transferToAddressETH(payable(_marketingAddress), ethForMarketing.mul(90).div(100));
       transferToAddressETH(payable(_treasuryAddress), ethForTreasury.mul(90).div(100));
       transferToAddressETH(payable(_foundationAddress), ethForFoundation.mul(90).div(100));

       addLiquidity(otherHalf, ethForLiquidity);
       _tokenAmountForFoundationTax = 0;
       _tokenAmountForLiquidityTax = 0;
       _tokenAmountForMarketingTax = 0;
       _tokenAmountForTreasuryTax = 0;

       
       emit SwapAndLiquify(half, newBalance, otherHalf);
    }

    function swapTokensForEth(uint256 tokenAmount) internal {

       address[] memory path = new address[](2);
       path[0] = address(this);
       path[1] = uniswapV2Router.WETH();

       _approve(address(this), address(uniswapV2Router), tokenAmount);

       uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
           tokenAmount,
           0, // accept any amount of ETH
           path,
           address(this),
           block.timestamp
       );
    }

    function addLiquidity(uint256 tokenAmount, uint256 ethAmount) internal {

       _approve(address(this), address(uniswapV2Router), tokenAmount);

       uniswapV2Router.addLiquidityETH{value: ethAmount}(
           address(this),
           tokenAmount,
           0, // slippage is unavoidable
           0, // slippage is unavoidable
           owner(),
           block.timestamp
       );
    }

    function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee) internal {
       if(!takeFee) {
          removeAllTax();
       } else if (automatedMarketMakerPairs[sender]) {
           setTaxBuyTax();
       } else  {
           setTaxSellTax();
       } 
           
       if (_isExcluded[sender] && !_isExcluded[recipient]) {
           _transferFromExcluded(sender, recipient, amount);
       } else if (!_isExcluded[sender] && _isExcluded[recipient]) {
           _transferToExcluded(sender, recipient, amount);
       } else if (!_isExcluded[sender] && !_isExcluded[recipient]) {
           _transferStandard(sender, recipient, amount);
       } else if (_isExcluded[sender] && _isExcluded[recipient]) {
           _transferBothExcluded(sender, recipient, amount);
       } else {
           _transferStandard(sender, recipient, amount);
       }      
    }

    function removeAllTax() internal {                 
       _reflectionTax = 0;
       _liquidityTax = 0;
       _marketingTax = 0;
       _treasuryTax = 0;
       _foundationTax = 0;
       _totalTax = 0;
    }
   
    function setTaxBuyTax() internal {
      _reflectionTax = _reflectionBuyTax;
      _liquidityTax = _liquidityBuyTax;
      _marketingTax = _marketingBuyTax;
      _treasuryTax = _treasuryBuyTax;
      _foundationTax = _foundationBuyTax;
      _totalTax = _liquidityTax.add(_marketingTax).add(_treasuryTax).add(_foundationTax);

    }

    function setTaxSellTax() internal {
      _reflectionTax = _reflectionSellTax;
      _liquidityTax = _liquiditySellTax;
      _marketingTax = _marketingSellTax;
      _treasuryTax = _treasurySellTax;
      _foundationTax = _foundationSellTax;
      _totalTax = _liquidityTax.add(_marketingTax).add(_treasuryTax).add(_foundationTax);
    }

    function _transferStandard(address sender, address recipient, uint256 tAmount) private {
        (uint256 rAmount, uint256 rTransferAmount, uint256 rReflection, uint256 tTransferAmount, uint256 tReflection, uint256 tTotal) = _getValues(tAmount);
        _rOwned[sender] = _rOwned[sender].sub(rAmount);
        _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
        
        if(_totalTax > 0) {
           _takeLiquidity(tTotal.mul(_liquidityTax).div(_totalTax));
           _takeMarketing(tTotal.mul(_marketingTax).div(_totalTax));
           _takeTreasury(tTotal.mul(_treasuryTax).div(_totalTax));
           _takeFoundation(tTotal.mul(_foundationTax).div(_totalTax));
        }        
        _reflectTax(rReflection, tReflection);
        emit Transfer(sender, recipient, tTransferAmount);
    }

    function _transferToExcluded(address sender, address recipient, uint256 tAmount) private {
        (uint256 rAmount, uint256 rTransferAmount, uint256 rReflection, uint256 tTransferAmount, uint256 tReflection, uint256 tTotal) = _getValues(tAmount);
        _rOwned[sender] = _rOwned[sender].sub(rAmount);
        _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
        _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount); 

        if(_totalTax > 0) {
           _takeLiquidity(tTotal.mul(_liquidityTax).div(_totalTax));
           _takeMarketing(tTotal.mul(_marketingTax).div(_totalTax));
           _takeTreasury(tTotal.mul(_treasuryTax).div(_totalTax));
           _takeFoundation(tTotal.mul(_foundationTax).div(_totalTax));
        }        
        _reflectTax(rReflection, tReflection);
        emit Transfer(sender, recipient, tTransferAmount);
    }

    function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private {
        (uint256 rAmount, uint256 rTransferAmount, uint256 rReflection, uint256 tTransferAmount, uint256 tReflection, uint256 tTotal) = _getValues(tAmount);
        _tOwned[sender] = _tOwned[sender].sub(tAmount);
        _rOwned[sender] = _rOwned[sender].sub(rAmount);
        _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);

        if(_totalTax > 0) {
           _takeLiquidity(tTotal.mul(_liquidityTax).div(_totalTax));
           _takeMarketing(tTotal.mul(_marketingTax).div(_totalTax));
           _takeTreasury(tTotal.mul(_treasuryTax).div(_totalTax));
           _takeFoundation(tTotal.mul(_foundationTax).div(_totalTax));
        }        
        _reflectTax(rReflection, tReflection);
        emit Transfer(sender, recipient, tTransferAmount);
    }

    function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private {
        (uint256 rAmount, uint256 rTransferAmount, uint256 rReflection, uint256 tTransferAmount, uint256 tReflection, uint256 tTotal) = _getValues(tAmount);
        _tOwned[sender] = _tOwned[sender].sub(tAmount);
        _rOwned[sender] = _rOwned[sender].sub(rAmount);
        _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
        _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);

        if(_totalTax > 0) {
           _takeLiquidity(tTotal.mul(_liquidityTax).div(_totalTax));
           _takeMarketing(tTotal.mul(_marketingTax).div(_totalTax));
           _takeTreasury(tTotal.mul(_treasuryTax).div(_totalTax));
           _takeFoundation(tTotal.mul(_foundationTax).div(_totalTax));
        }        
        _reflectTax(rReflection, tReflection);
        emit Transfer(sender, recipient, tTransferAmount);
    }

    function _takeLiquidity(uint256 tLiquidity) private {
        uint256 currentRate =  _getRate();
        uint256 rLiquidity = tLiquidity.mul(currentRate);
        _tokenAmountForLiquidityTax += tLiquidity;
        _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity);
        if(_isExcluded[address(this)])
            _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity);
    }

    function _takeMarketing(uint256 tMarketing) private {
        uint256 currentRate = _getRate();
        uint256 rMarketing = tMarketing.mul(currentRate);
        _tokenAmountForMarketingTax += tMarketing;
        _rOwned[address(this)] = _rOwned[address(this)].add(rMarketing);
        if(_isExcluded[address(this)])
            _tOwned[address(this)] = _tOwned[address(this)].add(tMarketing);
    }

    function _takeTreasury(uint256 tTreasury) private {
        uint256 currentRate = _getRate();
        uint256 rTreasury = tTreasury.mul(currentRate);
        _tokenAmountForTreasuryTax += tTreasury;
        _rOwned[address(this)] = _rOwned[address(this)].add(rTreasury);
        if(_isExcluded[address(this)])
            _tOwned[address(this)] = _tOwned[address(this)].add(tTreasury);
    }

    function _takeFoundation(uint256 tFoundation) private {
        uint256 currentRate = _getRate();
        uint256 rFoundation = tFoundation.mul(currentRate);
        _tokenAmountForFoundationTax += tFoundation;
        _rOwned[address(this)] = _rOwned[address(this)].add(rFoundation);
        if(_isExcluded[address(this)])
            _tOwned[address(this)] = _tOwned[address(this)].add(tFoundation);
    }

    function _reflectTax(uint256 rReflection, uint256 tReflection) private {
       _rTotal = _rTotal.sub(rReflection);
       _tFeeTotal = _tFeeTotal.add(tReflection);
    }

    function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) {
       (uint256 tTransferAmount, uint256 tReflection, uint256 tTotal) = _getTValues(tAmount);
       (uint256 rAmount, uint256 rTransferAmount, uint256 rReflection) = _getRValues(tAmount, tReflection, tTotal, _getRate());
       return (rAmount, rTransferAmount, rReflection, tTransferAmount, tReflection, tTotal);
    }

    function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) {
       uint256 tReflection = calculateReflectionTax(tAmount);
       uint256 tTotal = calculateTotalTax(tAmount);
       uint256 tTransferAmount = tAmount.sub(tReflection).sub(tTotal);
       return (tTransferAmount, tReflection, tTotal);
    }

    function _getRValues(uint256 tAmount, uint256 tReflection, uint256 tTotal, uint256 currentRate) private pure returns (uint256, uint256, uint256) {
       uint256 rAmount = tAmount.mul(currentRate);
       uint256 rReflection = tReflection.mul(currentRate);
       uint256 rTotal = tTotal.mul(currentRate);
       uint256 rTransferAmount = rAmount.sub(rReflection).sub(rTotal);
       return (rAmount, rTransferAmount, rReflection);
    }

    function _getRate() private view returns(uint256) {
       (uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
       return rSupply.div(tSupply);
    }

    function _getCurrentSupply() private view returns(uint256, uint256) {
       uint256 rSupply = _rTotal;
       uint256 tSupply = _tTotal;      
       for (uint256 i = 0; i < _excluded.length; i++) {
           if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal);
           rSupply = rSupply.sub(_rOwned[_excluded[i]]);
           tSupply = tSupply.sub(_tOwned[_excluded[i]]);
       }
       if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal);
       return (rSupply, tSupply);
    }

    function calculateReflectionTax(uint256 _amount) private view returns (uint256) {
       return _amount.mul(_reflectionTax).div(
           10**2
       );
    }

    function calculateTotalTax(uint256 _amount) private view returns (uint256) {
       return _amount.mul(_totalTax).div(
           10**2
       );
    }
        
   // External Read functions 
    function tokenFromReflection(uint256 rAmount) public view returns(uint256) {
       require(rAmount <= _rTotal, "Amount must be less than total reflections");
       uint256 currentRate =  _getRate();
       return rAmount.div(currentRate);
    }

    function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) {
       require(tAmount <= _tTotal, "Amount must be less than supply");
       if (!deductTransferFee) {
           (uint256 rAmount,,,,,) = _getValues(tAmount);
           return rAmount;
       } else {
           (,uint256 rTransferAmount,,,,) = _getValues(tAmount);
           return rTransferAmount;
       }
    }          

    function isExcludedFromReward(address account) public view returns (bool) {
        return _isExcluded[account];
    }

    function totalFees() public view returns (uint256) {
        return _tFeeTotal;
    }

    function deliver(uint256 tAmount) public {
        address sender = _msgSender();
        require(!_isExcluded[sender], "Excluded addresses cannot call this function");
        (uint256 rAmount,,,,,) = _getValues(tAmount);
        _rOwned[sender] = _rOwned[sender].sub(rAmount);
        _rTotal = _rTotal.sub(rAmount);
        _tFeeTotal = _tFeeTotal.add(tAmount);
    }

    function isExcludedFromFee(address account) public view returns(bool) {
       return _isExcludedFromFee[account];
    }

    function gettansactionDataAmount(address account) public view returns(uint256) {
        return transactionData[account].amount;
    }//

    function gettransactionDataTime(address account) public view returns(uint256) {
        return transactionData[account].timeStamp;
    }

    function getTransactionDataIsLocked(address account) public view returns(bool) {
        return transactionData[account].isLocked;
    }

    function getTransactionDataLockedTime(address account) public view returns(uint256) {
        return transactionData[account].lockedTime;
    }

    function getTransactionDataLockedPeriod(address account) public view returns(uint256) {
        return transactionData[account].lockPeriod;
    }

    function transferToAddressETH(address payable recipient, uint256 amount) private {
        recipient.transfer(amount);
    }

    // Write functions

    function excludeFromReward(address account) public onlyOwner() {
        require(!_isExcluded[account], "Account is already excluded");
        if(_rOwned[account] > 0) {
            _tOwned[account] = tokenFromReflection(_rOwned[account]);
        }
        _isExcluded[account] = true;
        _excluded.push(account);

        emit ExcludeFromReward(account);
    }

    function includeInReward(address account) external onlyOwner() {
        require(_isExcluded[account], "Account is already included");
        for (uint256 i = 0; i < _excluded.length; i++) {
            if (_excluded[i] == account) {
                _excluded[i] = _excluded[_excluded.length - 1];
                _tOwned[account] = 0;
                _isExcluded[account] = false;
                _excluded.pop();
                break;
            }
        }

        emit IncludeInReward(account);
    }
    
    function excludeFromFee(address account) public onlyOwner() {
        _isExcludedFromFee[account] = true;

        emit ExcludeFromFee(account);
    }
    
    function includeInFee(address account) public onlyOwner() {
        _isExcludedFromFee[account] = false;

        emit IncludeInFee(account);
    }
    
    function setBuyTaxPercent(uint256 reflectionBuyTax, uint256 liquidityBuyTax, uint256 marketingBuyTax, uint256 treasuryBuyTax, uint256 foundationBuyTax) external onlyOwner() {
        _reflectionBuyTax = reflectionBuyTax;
        _liquidityBuyTax = liquidityBuyTax;
        _marketingBuyTax = marketingBuyTax;
        _treasuryBuyTax = treasuryBuyTax;
        _foundationBuyTax = foundationBuyTax;

        emit BuyTaxPercnetUpdate(reflectionBuyTax, liquidityBuyTax, marketingBuyTax, treasuryBuyTax, foundationBuyTax);
    }
    
    function setSellTaxPercent(uint256 reflectionSellTax, uint256 liquiditySellTax, uint256 marketingSellTax, uint256 treasurySellTax, uint256 foundationSellTax) external onlyOwner() {
        _reflectionSellTax = reflectionSellTax;
        _liquiditySellTax = liquiditySellTax;
        _marketingSellTax = marketingSellTax;
        _treasurySellTax = treasurySellTax;
        _foundationSellTax = foundationSellTax;

        emit SellTaxPercent(reflectionSellTax, liquiditySellTax, marketingSellTax, treasurySellTax, foundationSellTax);
    }

    function setMarketingAddress(address marketingAddress) external onlyOwner() {
       _marketingAddress = marketingAddress;

       emit MarketingAddressUpdate(marketingAddress);
    }
    
    function setTreasuryAddress(address treasuryAddress) external onlyOwner() {
       _treasuryAddress = treasuryAddress;

       emit TreasuryAddressUpdate(treasuryAddress);
    }

    
    function setFoundationAddress(address foundationAddress) external onlyOwner() {
       _foundationAddress = foundationAddress;

       emit FoundationAddressUpdate(foundationAddress);
    }        

    function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner() {
        swapAndLiquifyEnabled = _enabled;

        emit SwapAndLiquifyEnabledUpdated(_enabled);
    }

    function setEnableTrading(bool tradingActive) external onlyOwner() {
       _tradingActive = tradingActive;

       emit EnableTradingUpdate(tradingActive);
    }

    function setNumTokensSellToAddToLiquidityPercentageAndmaxwalletamount(uint256 _numTokensSellToAddToLiquidityPercentage, uint256 _maxwalletamountPercentage) external onlyOwner() {
       numTokensSellToAddToLiquidity = _tTotal.mul(_numTokensSellToAddToLiquidityPercentage).div(10000);
       _maxwalletamount = _tTotal.mul(_maxwalletamountPercentage).div(10000);

       emit NumTokenSellToAddToLiquidityPercentageAndMaxwalletAmount(_numTokensSellToAddToLiquidityPercentage, _maxwalletamountPercentage);
    }

    function setDailymaxTxAmountAndmaxTxAmount(uint256 dailymaxTxAmount, uint256 maxTxAmount) external onlyOwner() {
        _dailymaxTxAmount = dailymaxTxAmount * 10 ** _decimals;
        _maxTxAmount = maxTxAmount * 10 ** _decimals;

        emit DaiyMaxTxAmountAndMaxTxAmountUpdate(dailymaxTxAmount, maxTxAmount);
    }

    function setAutomatedMarketMakerPairs(address newPair) external onlyOwner() {
       automatedMarketMakerPairs[newPair] = true;

       emit AutomatedMarketMakerPairsUpdate(newPair);
    }

    function lockAccount(address account, uint256 lockPeriod) external onlyOwner() {
        transactionData[account].isLocked = true;
        transactionData[account].lockedTime = block.timestamp;
        transactionData[account].lockPeriod = lockPeriod * 86400;
        emit LockAccount(account, true, lockPeriod);
    }

    function unLockAccount(address account) external onlyOwner() {
        transactionData[account].isLocked = false;
        transactionData[account].lockedTime = 0;
        transactionData[account].lockPeriod = 0;
        emit UnlockAccount(account, false);
    }

    function SetAccountMaxWalletLimit(address account, bool enabled) external onlyOwner() {
        _isExcludedMaxTransactionAmount[account] = enabled;
        emit UpdateAccountMaxWalletLimit(account, enabled);
    }

    function airdrop(address recipient, uint256 amount) external onlyOwner() {
       _transfer(_msgSender(), recipient, amount * 10**18);
    }
   
    function airdropInternal(address recipient, uint256 amount) internal {
       _transfer(_msgSender(), recipient, amount);
    }
   
    function airdropArray(address[] calldata newholders, uint256[] calldata amounts) external onlyOwner(){
       uint256 iterator = 0;
       require(newholders.length == amounts.length, "must be the same length");
       while(iterator < newholders.length){
           airdropInternal(newholders[iterator], amounts[iterator] * 10**18);
           iterator += 1;
       }
    }

    receive() external payable {}

}
function name() public view returns (string memory) {
        return _name;
    }
// ERC-20 standard functions