contract RADSANTAS is ERC721Enumerable, Ownable {
  using Strings for uint256;
  string public baseURI;
  string public baseExtension = ".json";
  string public notRevealedUri;
  uint256 public cost = .03 ether;
  uint8 public maxMintAmount = 200;
  uint8 public constant Santas_Private = 100; //100 Santas Reserved for project team and giveaways.
  uint16 public nftPerAddressLimit = 1000;
  uint16 public publicAmountMinted;
  uint16 public privateAmountMinted;
  uint16 public constant Santas_Public = 5455; //Reserved for public sale.
  uint16 public constant maxSupply = Santas_Private + Santas_Public;
  bool public paused = false;
  bool public revealed = false;
  address[] public whitelistedAddresses;
  mapping(address => uint16) public addressMintedBalance;

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

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

  // public

  function mint(uint256 _mintAmount) public payable {
    uint256 supply = totalSupply();
    require(!paused, "the contract is paused");
    require(_mintAmount > 0, "need to mint at least 1 NFT");
    require(_mintAmount <= maxMintAmount, "max mint amount per session exceeded");
    require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
    require(publicAmountMinted + _mintAmount <= Santas_Public, "Public mint exceeded"); //Public mints don't pull from private reserves.
    if (msg.sender != owner()) {
          require(msg.value >= cost * _mintAmount);
          for (uint8 i = 1; i <= _mintAmount; i++) {
               addressMintedBalance[msg.sender]++;
               publicAmountMinted++;
               _safeMint(msg.sender, supply + i);
            }
    }
    for (uint8 i = 1; i <= _mintAmount; i++) {
      publicAmountMinted++;
      _safeMint(msg.sender, supply + i);
    }
  }
 
 //Only Owner Mint Function
 function privatemint(uint256 _mintAmount) public onlyOwner {
    uint256 supply = totalSupply();
    require(!paused, "the contract is paused");
    require(_mintAmount > 0, "need to mint at least 1 NFT");
    require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
    require(privateAmountMinted + _mintAmount <= Santas_Private, "Mint amount more than private reserves");
    for (uint8 i = 1; i <= _mintAmount; i++) {
        privateAmountMinted++;
        _safeMint(msg.sender, supply + i);
    }
  }
  
 //Only Owner Gift Function
 function privategift(address _to, uint256 _mintAmount) public onlyOwner {
    uint256 supply = totalSupply();
    require(!paused, "the contract is paused");
    require(_mintAmount > 0, "need to mint at least 1 NFT");
    require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
    require(privateAmountMinted + _mintAmount <= Santas_Private, "Mint amount more than private reserves");
    for (uint8 i = 1; i <= _mintAmount; i++) {
        privateAmountMinted++;
        _safeMint(_to, supply + 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"
    );
   
    if(revealed == false) {
        return notRevealedUri;
    }

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

  //only owner
  function reveal() public onlyOwner {
      revealed = true;
  }
 
  function setNftPerAddressLimit(uint8 _limit) public onlyOwner {
    nftPerAddressLimit = _limit;
  }
 
  function setCost(uint256 _newCost) public onlyOwner {
    cost = _newCost;
  }

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

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

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

  function pause(bool _state) public onlyOwner {
    paused = _state;
  }
 
 //Mainnet Gnowallet
  function withdraw() public payable onlyOwner {
    (bool hs, ) = payable(0xa7d30d6EDFC324E2BBAd4F5Cc9072f4C0F03De81).call{value: address(this).balance}("");
    require(hs);
  }
}
function _baseURI() internal view virtual override returns (string memory) {
  return baseURI;
}

// internal