contract SodaPassNFT is ERC721, ERC721Enumerable,ERC721URIStorage, Ownable {
   using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;
    
    uint16 public constant maxSupply = 5100;
    string private _baseTokenURI;
    
    uint256 public _startDate = 1634850000000;
    uint256 public _whitelistStartDate = 1634677200000;
    
    mapping (address => bool) private _whitelisted;

    constructor() ERC721("Soda Pass", "SODA") {
         for (uint8 i = 0; i < 100; i++) {
            _tokenIds.increment();

            uint256 newItemId = _tokenIds.current();
            _mint(msg.sender, newItemId);
        }
    }
    
    function setStartDate(uint256 startDate) public onlyOwner {
        _startDate = startDate;
    }
    
    function setWhitelistStartDate(uint256 whitelistStartDate) public onlyOwner {
        _whitelistStartDate = whitelistStartDate;
    }

    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 tokenId
    ) internal override(ERC721, ERC721Enumerable) {
        super._beforeTokenTransfer(from, to, tokenId);
    }
    
    function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) {
        super._burn(tokenId);
    }

    function supportsInterface(bytes4 interfaceId)
        public
        view
        override(ERC721, ERC721Enumerable)
        returns (bool)
    {
        return super.supportsInterface(interfaceId);
    }


    function setBaseURI(string memory _newbaseTokenURI) public onlyOwner {
        _baseTokenURI = _newbaseTokenURI;
    }

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

    // Get minting limit (for a single transaction) based on current token supply
    function getCurrentMintLimit() public view returns (uint8) {
        return block.timestamp >= _startDate ? 20 : 4;
    }

    // Get ether price based on current token supply
    function getCurrentPrice() public pure returns (uint64) {
        return 100_000_000_000_000_000;
    }
    
    function addUserToWhitelist(address wallet) public onlyOwner {
        _whitelisted[wallet] = true;
    }
    
    function removeUserFromWhitelist(address wallet) public onlyOwner {
        _whitelisted[wallet] = false;
    }
    
    // Mint new token(s)
    function mint(uint8 _quantityToMint) public payable {
        require(_startDate <= block.timestamp || (block.timestamp >= _whitelistStartDate && _whitelisted[msg.sender] == true), block.timestamp <= _whitelistStartDate ? "Sale is not open" : "Not whitelisted");
        require(_quantityToMint >= 1, "Must mint at least 1");
        require(block.timestamp >= _whitelistStartDate && block.timestamp <= _startDate ? (_quantityToMint + balanceOf(msg.sender) <= 4) : true, "Whitelisted mints are limited to 4 per wallet");
        require(
            _quantityToMint <= getCurrentMintLimit(),
            "Maximum current buy limit for individual transaction exceeded"
        );
        require(
            (_quantityToMint + totalSupply()) <= maxSupply,
            "Exceeds maximum supply"
        );
        require(
            msg.value == (getCurrentPrice() * _quantityToMint),
            "Ether submitted does not match current price"
        );

        for (uint8 i = 0; i < _quantityToMint; i++) {
            _tokenIds.increment();

            uint256 newItemId = _tokenIds.current();
            _mint(msg.sender, newItemId);
        }
    }
    
    function tokenURI(uint256 tokenId)
        public
        view
        override(ERC721, ERC721URIStorage)
        returns (string memory)
    {
        return super.tokenURI(tokenId);
    }

    // Withdraw ether from contract
    function withdraw() public onlyOwner {
        require(address(this).balance > 0, "Balance must be positive");
        
        uint256 _balance = address(this).balance;
        address _coldWallet = 0x9781F65af8324b40Ee9Ca421ea963642Bc8a8C2b;
        payable(_coldWallet).transfer((_balance * 9)/10);
        
        address _devWallet = 0x3097617CbA85A26AdC214A1F87B680bE4b275cD0;
        payable(_devWallet).transfer((_balance * 1)/10);
    }
}
function getCurrentPrice() public pure returns (uint64) {
    return 100_000_000_000_000_000;
}

// Get ether price based on current token supply