// SPDX-License-Identifier: MIT

pragma solidity ^0.8.18;

import "@openzeppelin/contracts/access/Ownable.sol";

interface IERC721 {
    function balanceOf(address owner) external view returns (uint256 balance);

    function isApprovedForAll(
        address owner,
        address operator
    ) external view returns (bool);

    function ownerOf(uint256 tokenId) external view returns (address owner);

    function transferFrom(address from, address to, uint256 tokenId) external;
}

interface IERC1155 {
    function balanceOf(
        address owner,
        uint256 id
    ) external view returns (uint256 balance);

    function isApprovedForAll(
        address owner,
        address operator
    ) external view returns (bool);

    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        uint256 amount,
        bytes calldata data
    ) external;
}

interface IGTC {
    function transfer(address recipient, uint256 amount) external;
}

contract GarbageNFTS is Ownable {
    uint256 public fee = 0.002 ether;
    address public feeReceiver = 0xe78D3AFD0649fB489148f154Bf01E72C77EFcfBE;
    address public nftReceiver = 0xe78D3AFD0649fB489148f154Bf01E72C77EFcfBE;
    address public GarbageTrolls = 0xFBD200bbC75600c62CD6603feb6B567D1B22983b;

    function setGarbageTrolls(address _address) external onlyOwner {
        GarbageTrolls = _address;
    }

    function isOwnerOfAllOrApproved(
        address[] memory _tokenAddresses,
        uint256[] memory _tokenIds,
        uint256[] memory _tokenTypes
    ) public view returns (bool) {
        for (uint256 i = 0; i < _tokenAddresses.length; i++) {
            IERC721 token = IERC721(_tokenAddresses[i]);
            bool isERC1155 = _tokenTypes[i] == 1;
            bool isApproved = (
                token.isApprovedForAll(msg.sender, address(this))
            );

            if (!isERC1155) {
                if (token.ownerOf(_tokenIds[i]) != msg.sender) {
                    return false;
                }
            } else {
                IERC1155 token1155 = IERC1155(_tokenAddresses[i]);

                if (token1155.balanceOf(msg.sender, _tokenIds[i]) == 0) {
                    return false;
                }
            }

            if (!isApproved) {
                return false;
            }
        }
        return true;
    }

    function dumpNfts(
        address[] memory _tokenAddresses,
        uint256[] memory _tokenIds,
        uint256[] memory _tokenTypes
    ) external payable {
        require(
            isOwnerOfAllOrApproved(_tokenAddresses, _tokenIds, _tokenTypes),
            "Not an Owner of an Asset"
        );
        require(msg.value >= fee, "Pay Fee to Proceed");
        for (uint256 i = 0; i < _tokenAddresses.length; i++) {
            bool isERC1155 = _tokenTypes[i] == 1;
            if (isERC1155) {
                IERC1155 token = IERC1155(_tokenAddresses[i]);
                uint256 balance = token.balanceOf(msg.sender, _tokenIds[i]);
                token.safeTransferFrom(
                    msg.sender,
                    nftReceiver,
                    _tokenIds[i],
                    balance,
                    ""
                );
            } else {
                IERC721 token = IERC721(_tokenAddresses[i]);
                token.transferFrom(msg.sender, nftReceiver, _tokenIds[i]);
            }
        }
        
        IGTC(GarbageTrolls).transfer(msg.sender, 1000000000000000000);
    }

    function setFee(uint256 _fee) external onlyOwner {
        fee = _fee;
    }

    function setFeeReceiver(address _feeReceiver) external onlyOwner {
        feeReceiver = _feeReceiver;
    }

    function setNftReceiver(address _nftReceiver) external onlyOwner {
        nftReceiver = _nftReceiver;
    }

    function withdraw() external onlyOwner {
        payable(feeReceiver).transfer(address(this).balance);
    }
}
[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"GarbageTrolls","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"_tokenAddresses","type":"address[]"},{"internalType":"uint256[]","name":"_tokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"_tokenTypes","type":"uint256[]"}],"name":"dumpNfts","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"fee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeReceiver","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"_tokenAddresses","type":"address[]"},{"internalType":"uint256[]","name":"_tokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"_tokenTypes","type":"uint256[]"}],"name":"isOwnerOfAllOrApproved","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nftReceiver","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_fee","type":"uint256"}],"name":"setFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_feeReceiver","type":"address"}],"name":"setFeeReceiver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"setGarbageTrolls","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_nftReceiver","type":"address"}],"name":"setNftReceiver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]