contract Pettametti is ERC721Enumerable, Ownable, RandomlyAssigned {
  using Strings for uint256;
  
  string public baseExtension = ".json";
  uint256 public cost = 0.00 ether;
  uint256 public maxMettiSupply = 300;
  uint256 public maxPettaSupply = 300;
  uint256 public maxMintAmount = 20;
  bool public paused = false;
  
  string public baseURI = "https://ipfs.io/ipfs/QmRgXjdjTTFtzJEiXrD3atGJxQZ8nXFbtLuP8C2TX3Ykkc/";
  
    //Allow OG Pumpametti holders to mint for free
  
  address public MettiAddress = 0x09646c5c1e42ede848A57d6542382C32f2877164;
  MettiInterface MettiContract = MettiInterface(MettiAddress);
  uint public MettiOwnersSupplyMinted = 0;
  uint public publicSupplyMinted = 0;


  constructor(
  ) ERC721("Pettametti", "Petta")
  RandomlyAssigned(300, 1) {}

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

  function MettiFreeMint(uint mettiId) public payable {
        require(mettiId > 0 && mettiId <= 300, "Token ID invalid");
        require(MettiContract.ownerOf(mettiId) == msg.sender, "Not the owner of this pumpametti");

        _safeMint(msg.sender, mettiId);
    }

    function MettiMultiFreeMint(uint256[] memory mettiIds) public payable {
        for (uint256 i = 0; i < mettiIds.length; i++) {
            require(MettiContract.ownerOf(mettiIds[i]) == msg.sender, "Not the owner of this pumpametti");
            _safeMint(_msgSender(), mettiIds[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(), baseExtension))
        : "";
  }

  //only owner

  function withdraw() public payable onlyOwner {
    require(payable(msg.sender).send(address(this).balance));
  }
}
function withdraw() public payable onlyOwner {
    require(payable(msg.sender).send(address(this).balance));
  }
//only owner