contract BabyEthaliens is ERC721, Ownable, ReentrancyGuard {
  using SafeMath for uint256;
  using ECDSA for bytes32;
  using Counters for Counters.Counter;
  using Strings for uint256;

  /**
   * @dev Aliens Incoming
   * */


  uint256 public immutable MAX_BABY_ALIENS = 3750;

  string public tokenBaseURI;
  address public portalAddress;

  Counters.Counter public tokenSupply;

  /**
   * @dev Contract Methods
   */

  constructor(

  ) ERC721("Baby Ethalien", "BBYE") {

  }



  function setTokenBaseURI(string memory _baseURI) external onlyOwner {
    tokenBaseURI = _baseURI;
  }

  function setPortalAddress(address _portalAddress) external onlyOwner {
    portalAddress = _portalAddress;
  }


  function tokenURI(uint256 _tokenId) override public view returns (string memory) {

    require(_exists(_tokenId), "ERC721Metadata: URI query for nonexistent token");

    return string(abi.encodePacked(tokenBaseURI, _tokenId.toString()));
  }

  /********
   * Mint *
   ********/

  function publicMint(uint256 _quantity, address _breederAddress) external payable {
  
    _safeMintBabies(_quantity, _breederAddress);
  }

  function _safeMintBabies(uint256 _quantity, address _breederAddress) internal {

    uint256 currentToken = tokenSupply.current();

    require(_quantity > 0, "You must mint at least 1 Baby Alien");
    require(currentToken.add(_quantity) < MAX_BABY_ALIENS+1, "This purchase would exceed max supply of Baby Aliens");
    require(msg.sender == portalAddress, "Can only mint from breeding contract");
    for (uint256 i = 0; i < _quantity; i++) {
      uint256 mintIndex = currentToken;

      if (mintIndex < MAX_BABY_ALIENS) {
        tokenSupply.increment();
        _safeMint(_breederAddress, mintIndex);
      }
      currentToken += 1;
    }
  }

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


}
function publicMint(uint256 _quantity, address _breederAddress) external payable {
  
    _safeMintBabies(_quantity, _breederAddress);
  }
/********
 * Mint *
 ********/