pragma solidity ^0.8.7;




contract WAItokenclaim  {
    ERC721 internal immutable nft;
    address public owner;
    uint256 public balance;
    //uint256 public amount = 1000000000000000000;
    
    uint256 public maxSupply = 7000;
    uint256 public standardAmount = 5555000000000000000000;
    uint256 public deluxeAmount = 8333000000000000000000;
    uint256 public villaAmount = 11111000000000000000000;
    uint256 public executiveAmount = 22222000000000000000000;

    event TransferReceived(address _from, uint _amount);
    event TransferSent(address _from, address _destAddr, uint _amount);
    event Claimed(uint256 indexed tokenId, address indexed claimer);

    mapping(uint256 => bool) public hasClaimed;
    error NotOwner();
    error AlreadyRedeemed();


    constructor(ERC721 _nft) {
        owner = msg.sender;
        nft = _nft;
    }
    
    receive() payable external {
        balance += msg.value;
        emit TransferReceived(msg.sender, msg.value);
    }    

    function updateAmount(uint256 _supply) internal view returns (uint256 _cost) {
        if(_supply <= 3780) {
            return standardAmount;
        }
        if(_supply <= 6160) {
            return deluxeAmount;
        }
        if(_supply <= 6860) {
            return villaAmount;
        }
        if(_supply <= maxSupply) {
            return executiveAmount;
        }
    }

    function withdraw(IERC20 token, uint256 withrawamount) public {
        require(msg.sender == owner, "Only owner can withdraw funds"); 
        uint256 erc20balance = token.balanceOf(address(this));
        require(withrawamount <= erc20balance, "balance is low");
        token.transfer(msg.sender, withrawamount);
        erc20balance -= withrawamount;
        emit TransferSent(msg.sender, msg.sender, withrawamount);
    }
    function ercbalance(IERC20 token) public view returns (uint cbalance) {
        return token.balanceOf(address(this));
    }
    
    function isclaimed (uint256 tokenId) public view returns (bool claimednft) {
        if (hasClaimed[tokenId]) 
        {
            return true;
        }
        else{
            return false;
        }
    }
    function isClaimedArray (uint[] memory _nftlist) public view returns (uint[] memory _unclaimed) {
        for (uint256 i = 0; i < _nftlist.length; i++) {
            if (hasClaimed[_nftlist[i]]){
                //unclaimedlist.push(_nftlist[i]);
                delete _nftlist[i];
            } 
        }
        return _nftlist;
    }

    function transferERC20(IERC20 token,uint256 tokenId) public {
        if (nft.ownerOf(tokenId) != msg.sender) revert NotOwner();
        if (hasClaimed[tokenId]) revert AlreadyRedeemed();
        uint256 erc20balance = token.balanceOf(address(this));
        require(updateAmount(tokenId) <= erc20balance, "balance is low");
        hasClaimed[tokenId] = true;
        token.transfer(msg.sender, updateAmount(tokenId));
        emit TransferSent(msg.sender, msg.sender, updateAmount(tokenId));
    }    
}
[{"inputs":[{"internalType":"contract ERC721","name":"_nft","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyRedeemed","type":"error"},{"inputs":[],"name":"NotOwner","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"address","name":"claimer","type":"address"}],"name":"Claimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_from","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"TransferReceived","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_from","type":"address"},{"indexed":false,"internalType":"address","name":"_destAddr","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"TransferSent","type":"event"},{"inputs":[],"name":"balance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"deluxeAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"ercbalance","outputs":[{"internalType":"uint256","name":"cbalance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"executiveAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"hasClaimed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_nftlist","type":"uint256[]"}],"name":"isClaimedArray","outputs":[{"internalType":"uint256[]","name":"_unclaimed","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"isclaimed","outputs":[{"internalType":"bool","name":"claimednft","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"standardAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"villaAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"withrawamount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]