contract marvatars is ERC721Enumerable, Ownable{
    using SafeMath for uint256;
    using Address for address;
    using Strings for uint256;
    
    uint256 public NFT_PRICE = 80000000000000000; 
    uint256 public MAX_SUPPLY = 2520;
    uint public MAX_NFT_PURCHASE = 5;
    bool public saleIsActive = false;
    
    function setMAX_SUPPLY(uint256 _supply) public onlyOwner {
        MAX_SUPPLY = _supply;
    }
    
    function setNFT_PRICE(uint256 _price) public onlyOwner {
        NFT_PRICE = _price;
    }
    
    function flipSaleState() public onlyOwner {
        saleIsActive = !saleIsActive;
    }
        
    string private _baseURIExtended;
    mapping (uint256 => string) _tokenURIs;

    constructor() ERC721("marvatars.com","MARV"){}

    function withdraw() public onlyOwner {
        payable(msg.sender).transfer(address(this).balance);
    }


    function mint(uint numberOfTokensMax5) public payable {
        require(saleIsActive, "Sale is not active at the moment");
        require(numberOfTokensMax5 > 0, "Number of tokens can not be less than or equal to 0");
        require(totalSupply().add(numberOfTokensMax5) <= MAX_SUPPLY, "Purchase would exceed max supply");
        require(numberOfTokensMax5 <= MAX_NFT_PURCHASE,"Can only mint up to 5 per purchase");
        require(NFT_PRICE.mul(numberOfTokensMax5) >= msg.value, "Sent ether value is incorrect");

        for (uint i = 0; i < numberOfTokensMax5; i++) {
            _safeMint(msg.sender, totalSupply());
        }
        
        //bonus NFT 
        if(numberOfTokensMax5 == 5){
           _safeMint(msg.sender, totalSupply());
        }
         
    }

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

    // Sets base URI for all tokens, only able to be called by contract owner
    function setBaseURI(string memory baseURI_) external onlyOwner {
        _baseURIExtended = baseURI_;
    }

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

        // If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI.
        return string(abi.encodePacked( _baseURI(), tokenId.toString()));
    }
}
function setBaseURI(string memory baseURI_) external onlyOwner {
        _baseURIExtended = baseURI_;
    }
// Sets base URI for all tokens, only able to be called by contract owner