contract DoodCats is ERC721Enumerable, Ownable{
  using Strings for uint256;
  
  string baseURI;
  string public baseExtension =".json";
  string public notRevealedUri;
  uint256 public reserved = 3;
  uint256 public cost = 0.05 ether;
  uint256 public maxSupply = 3000;
  bool public saleActive = false;
  bool public revealed = false;
  
  constructor (
    string memory _initBaseURI,
    string memory _initNotRevealedUri)
    ERC721 ("Dood Cats", "DCATS") {
        setBaseURI(_initBaseURI);
        setNotRevealedURI(_initNotRevealedUri);
    }
  
  // internal
  function _baseURI() internal view virtual override returns (string memory) {
    return baseURI;
  }
  
  //PUBLIC functionality
    
    // Standard mint function
    function mint(uint256 _amount) public payable {
        uint256 supply = totalSupply();
        require( saleActive,                     "Sale isn't active" );
        require( _amount > 0 && _amount < 11,    "Can only mint between 1 and 10 tokens at once" );
        require( supply + _amount <= maxSupply, "Can't mint more than max supply" );
        require( msg.value == cost * _amount,   "Wrong amount of ETH sent" );
        for(uint256 i; i < _amount; i++){
            _safeMint( msg.sender, 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))
        : "";
  }
  
  //ADMIN FUNCTIONALITY 
  
  //Reveal Dood Cats
  function reveal() public onlyOwner() {
      revealed = true;
  }
  
    function mintReserved(uint256 _amount) public onlyOwner {
        require( _amount <= reserved, "Can't reserve more than set amount" );
        reserved -= _amount;
        uint256 supply = totalSupply();
        for(uint256 i; i < _amount; i++){
            _safeMint( msg.sender, supply + i );
        }
    }

    // Start and stop sale
    function setSaleActive(bool val) public onlyOwner {
        saleActive = val;
    }
    
    
    function setCost(uint256 _newCost) public onlyOwner() {
    cost = _newCost;
  }
  
    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 withdraw() public payable onlyOwner {
    (bool dc, ) = payable(owner()).call{value: address(this).balance}("");
    require(dc);
  }
}
function _baseURI() internal view virtual override returns (string memory) {
    return baseURI;
  }
// internal