contract EscapeOfficial is Ownable, ReentrancyGuard, ERC721A {
  using Strings for uint256;

  string private baseURI;
  string private baseExtension = ".json";
  uint256 private cost = 0.025 ether;
  uint256 public maxSupply = 6577;
  uint256 public maxMintAmount = 5;
  bool public saleIsActive = true;
  bool public revealed = false;
  string private notRevealedUri;
  uint256 numberOfFreeNFTs = 1000;
  mapping(address => bool) private whitelisted;

  constructor(
    string memory _name,
    string memory _symbol,
    string memory _initBaseURI,
    string memory _initNotRevealedUri
  ) ERC721A(_name, _symbol) {
    setBaseURI(_initBaseURI);
    setNotRevealedURI(_initNotRevealedUri);
  }

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

  // public
  function mint(uint256 _mintAmount) external payable {
    require(saleIsActive, "Sale is not active!");
    require(totalSupply() >= numberOfFreeNFTs, "Can not mint more than one until 1000 NFTs are minted!");
    require(balanceOf(msg.sender) + _mintAmount <= maxMintAmount, "Maximum 5 NFTs minted per wallet!");
    require(totalSupply() + _mintAmount <= maxSupply, "Not enough tokens left");
    require(msg.value >= (cost * _mintAmount), "Not enough ether sent");
    _safeMint(msg.sender, _mintAmount);
    payable(owner()).transfer(address(this).balance);
  }

  function mintOne() public payable {
    uint256 supply = totalSupply();
    require(saleIsActive, "Sale is not active!");
    require(balanceOf(msg.sender) < 1, "Can only mint once per wallet!");
    require(supply < numberOfFreeNFTs, "Total supply must not exceed number of free NFTs");
    _safeMint(msg.sender, 1);
  }

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

    if (revealed == false) {
        return bytes(notRevealedUri).length > 0
            ? string(abi.encodePacked(notRevealedUri, (tokenId + 1).toString(), baseExtension))
            : "";
    }

    string memory currentBaseURI = _baseURI();
    return bytes(currentBaseURI).length > 0
        ? string(abi.encodePacked(currentBaseURI, (tokenId + 1).toString(), baseExtension))
        : "";
  }

  //only owner
  function setReveal(bool value) public onlyOwner {
    revealed = value;
  }

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

  function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
    maxMintAmount = _newmaxMintAmount;
  }

  function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
    notRevealedUri = _notRevealedURI;
  }

  function setBaseURI(string memory _newBaseURI) public onlyOwner {
    baseURI = _newBaseURI;
  }

  function setBaseExtension(string memory _newBaseExtension) public onlyOwner {
    baseExtension = _newBaseExtension;
  }

  function setSaleIsActive(bool _state) public onlyOwner {
    saleIsActive = _state;
  }
 
  function whitelistUser(address _user) public onlyOwner {
    whitelisted[_user] = true;
  }

  function setNumberOfFreeNFTs(uint256 _number) public onlyOwner {
    numberOfFreeNFTs = _number;
  }

  function setMaxSupply(uint256 _number) public onlyOwner {
    maxSupply = _number;
  }
 
  function removeWhitelistUser(address _user) public onlyOwner {
    whitelisted[_user] = false;
  }

  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