contract genesizShapez is ERC721, Ownable {
  using Strings for uint256;
  using Counters for Counters.Counter;

  Counters.Counter private supply;

  string public uriPrefix = "";
  string public uriSuffix = ".json";
  string public hiddenMetadataUri;
  
  uint256 public cost = 0.0555 ether;
  uint256 public maxSupply = 3500;
  uint256 public maxMintAmountPerTx = 20;

  bool public paused = false;
  bool public revealed = true;

  address public rooAddress;
  uint256 public roosMinted;
  uint256 public maxRooMints;

  constructor() ERC721("Genesiz Shapez", "SHAPEZ") {
    setHiddenMetadataUri("https://evolutionz.art/nft/hidden.json");
    setUriPrefix("https://evolutionz.art/nft/");

    // set the contract address to RooTroop Contract
    setRooAddress(0x928f072C009727FbAd81bBF3aAa885f9fEa65fcf);
    //set amount of max roo mints
    setMaxRooMints(100);
  }

  modifier mintCompliance(uint256 _mintAmount) {
    require(_mintAmount > 0 && _mintAmount <= maxMintAmountPerTx, "Invalid mint amount!");
    require(supply.current() + _mintAmount <= maxSupply, "Max supply exceeded!");
    _;
  }

  function totalSupply() public view returns (uint256) {
    return supply.current();
  }


  function mint(uint256 _mintAmount) public payable mintCompliance(_mintAmount) {
    require(!paused, "The contract is paused!");

    // declare new custom token from address
    IERC721 rooToken = IERC721(rooAddress);
    // save roo tokens owned as variable
    uint256 rooAmountOwned = rooToken.balanceOf(msg.sender);

    // if roo holder, owns 0 Shapez and not fully free minted
    if (rooAmountOwned >= 1 && balanceOf(msg.sender) < 1 && roosMinted < maxRooMints) {
        require(msg.value >= cost * (_mintAmount - 1), "Insufficient funds!");
        roosMinted++;
    }   else {
        require(msg.value >= cost * _mintAmount, "Insufficient funds!");
    } 
    
    _mintLoop(msg.sender, _mintAmount);
  }

  
  
  function mintForAddress(uint256 _mintAmount, address _receiver) public mintCompliance(_mintAmount) onlyOwner {
    _mintLoop(_receiver, _mintAmount);
  }

  function walletOfOwner(address _owner)
    public
    view
    returns (uint256[] memory)
  {
    uint256 ownerTokenCount = balanceOf(_owner);
    uint256[] memory ownedTokenIds = new uint256[](ownerTokenCount);
    uint256 currentTokenId = 1;
    uint256 ownedTokenIndex = 0;

    while (ownedTokenIndex < ownerTokenCount && currentTokenId <= maxSupply) {
      address currentTokenOwner = ownerOf(currentTokenId);

      if (currentTokenOwner == _owner) {
        ownedTokenIds[ownedTokenIndex] = currentTokenId;

        ownedTokenIndex++;
      }

      currentTokenId++;
    }

    return ownedTokenIds;
  }


  function tokenURI(uint256 _tokenId)
    public
    view
    virtual
    override
    returns (string memory)
  {
    require(
      _exists(_tokenId),
      "ERC721Metadata: URI query for nonexistent token"
    );

    if (revealed == false) {
      return hiddenMetadataUri;
    }

    string memory currentBaseURI = _baseURI();
    return bytes(currentBaseURI).length > 0
        ? string(abi.encodePacked(currentBaseURI, _tokenId.toString(), uriSuffix))
        : "";
  }

  function setRevealed(bool _state) public onlyOwner {
    revealed = _state;
  }

  function setCost(uint256 _cost) public onlyOwner {
    cost = _cost;
  }

  function setMaxMintAmountPerTx(uint256 _maxMintAmountPerTx) public onlyOwner {
    maxMintAmountPerTx = _maxMintAmountPerTx;
  }

  function setHiddenMetadataUri(string memory _hiddenMetadataUri) public onlyOwner {
    hiddenMetadataUri = _hiddenMetadataUri;
  }

  function setUriPrefix(string memory _uriPrefix) public onlyOwner {
    uriPrefix = _uriPrefix;
  }

  function setUriSuffix(string memory _uriSuffix) public onlyOwner {
    uriSuffix = _uriSuffix;
  }

  function setPaused(bool _state) public onlyOwner {
    paused = _state;
  }

  function withdraw(uint256 _amount) public onlyOwner {

    (bool os, ) = payable(owner()).call{value: _amount }("");
    require(os);

  }

  function _mintLoop(address _receiver, uint256 _mintAmount) internal {
    for (uint256 i = 0; i < _mintAmount; i++) {
      supply.increment();
      _safeMint(_receiver, supply.current());
    }
  }

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


    // sets the contract address to Roo Troop
  function setRooAddress(address _newAddress) public onlyOwner{
    rooAddress = _newAddress;
  }

    //sets max amount of roos that can be minted
  function setMaxRooMints(uint256 _newAmount) public onlyOwner{
    maxRooMints = _newAmount;
  }
}
function setMaxRooMints(uint256 _newAmount) public onlyOwner{
  maxRooMints = _newAmount;
}

//sets max amount of roos that can be minted