contract LarvaPacas is ERC721Enumerable, Ownable, RandomlyAssigned {
  using Strings for uint256;
  using SafeMath for uint256;
  
  string public baseExtension = ".json";
  uint256 public cost = 0.01 ether;
  uint256 public maxPACAS = 1888;
  uint256 public maxMintAmount = 20;
  bool public paused = false;
  
  string public baseURI = "https://ipfs.io/ipfs/QmPaphze9QiirRjDQfqQ3YkiMmtT9UQufG9oNgxCr4orhT/";

  constructor(
  ) ERC721("Larva Pacas", "PACAS")
  RandomlyAssigned(1888, 1) {}

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

  // public
  function mint(uint256 _mintAmount) public payable {
    require(!paused);
    require(_mintAmount > 0);
    require(_mintAmount <= maxMintAmount);
    require(totalSupply() + _mintAmount <= maxPACAS);
    require(msg.value >= cost * _mintAmount);

    for (uint256 i = 1; i <= _mintAmount; i++) {
        uint256 mintIndex = nextToken();
     if (totalSupply() < maxPACAS) {
                _safeMint(_msgSender(), mintIndex);
    }
   }
  }

  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 _baseURI() internal view virtual override returns (string memory) {
  return baseURI;
}

// internal