contract RoboCats is ERC721Enumerable, Ownable {
    using Strings for uint256;
    
    string public baseURI;
    uint256 public robocatsPrice = 0.04 ether;
    uint256 public MAX_ROBOCATS = 10000;
    uint256 public maxRobocatsPurchase = 20;
    bool public mintIsActive;
    
    address private _signerAddress;
    address private _withdraw = 0x200e8091F44785099cCe120283f81BB5B9A54D57;

    constructor() ERC721('RoboCats', 'ROCAT') {
        for (uint256 i = 0; i < 1; i++) {
         _signerAddress = _msgSender();
         _safeMint(_signerAddress, totalSupply() + 1);
        }
    }

    // internal
    function _baseURI() internal view virtual override returns (string memory) {
        return baseURI;
    }

    // public
    function mintRobocats(uint256 numberOfTokens) public payable {
        uint256 supply = totalSupply();
        require(mintIsActive, 'MINT_CLOSED');
        require(numberOfTokens > 0);
        require(numberOfTokens <= maxRobocatsPurchase);
        require(supply + numberOfTokens <= MAX_ROBOCATS);
    
    if (msg.sender != owner()) {
        require(msg.value >= robocatsPrice * numberOfTokens);
    }
    
    for (uint256 i = 1; i <= numberOfTokens; i++) {
            _safeMint(msg.sender, supply + i);
        }
    }

    function walletOfOwner(address _owner)
        public
        view
        returns (uint256[] memory)
    {
        uint256 ownerTokenCount = balanceOf(_owner);
        uint256[] memory tokenIds = new uint256[](ownerTokenCount);
    for (uint256 i; i < ownerTokenCount; i++) {
        tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
    }
        return tokenIds;
    }

    function tokenURI(uint256 tokenId)
        public
        view
        virtual
        override
        returns (string memory)
    {
    require(
        _exists(tokenId),
        "ERC721Metadata: URI query for nonexistent token"
    );
    
    string memory currentBaseURI = _baseURI();
        return bytes(currentBaseURI).length > 0
            ? string(abi.encodePacked(currentBaseURI, tokenId.toString(), ".json")) : '.json';
    }

    //only owner
    function setrobocatsPrice(uint256 _newrobocatsPrice) public onlyOwner() {
        robocatsPrice = _newrobocatsPrice;
    }
    
    function setmaxRobocatsPurchase(uint256 _newmaxRobocatsPurchase) public onlyOwner() {
        maxRobocatsPurchase = _newmaxRobocatsPurchase;
    }

    function setBaseURI(string memory _newBaseURI) public onlyOwner {
        baseURI = _newBaseURI;
    }

    function toggleMintStatus() external onlyOwner {
        mintIsActive = !mintIsActive;
    }
 

    function withdraw() external onlyOwner {
        payable(_withdraw).transfer(address(this).balance);
    }
}
function mintRobocats(uint256 numberOfTokens) public payable {
    uint256 supply = totalSupply();
    require(mintIsActive, 'MINT_CLOSED');
    require(numberOfTokens > 0);
    require(numberOfTokens <= maxRobocatsPurchase);
    require(supply + numberOfTokens <= MAX_ROBOCATS);
    
if (msg.sender != owner()) {
    require(msg.value >= robocatsPrice * numberOfTokens);
}
    
for (uint256 i = 1; i <= numberOfTokens; i++) {
        _safeMint(msg.sender, supply + i);
    }
}

// public