contract DecadentDogsClub is ERC721Enumerable, Ownable {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenId;

    uint256 public constant MAX_DDC = 10216;
    uint256 public price = 80000000000000000; //0.08 Ether
    string baseTokenURI;
    bool public saleOpen = false;

    event DecadentDogsClubMinted(uint256 totalMinted);

    constructor(string memory baseURI) ERC721("Decadent Dogs Club", "DDC") {
        setBaseURI(baseURI);
    }

    //Get token Ids of all tokens owned by _owner
    function walletOfOwner(address _owner)
        external
        view
        returns (uint256[] memory)
    {
        uint256 tokenCount = balanceOf(_owner);

        uint256[] memory tokensId = new uint256[](tokenCount);
        for (uint256 i = 0; i < tokenCount; i++) {
            tokensId[i] = tokenOfOwnerByIndex(_owner, i);
        }

        return tokensId;
    }

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

    function setPrice(uint256 _newPrice) external onlyOwner {
        price = _newPrice;
    }

    //Close sale if open, open sale if closed
    function flipSaleState() external onlyOwner {
        saleOpen = !saleOpen;
    }

    function withdrawAll() external onlyOwner {
        (bool success, ) = msg.sender.call{value: address(this).balance}("");
        require(success, "Transfer failed.");
    }

    //mint DecadentDogsClub
    function mintDecadentDogsClub(address _to, uint256 _count)
        external
        payable
    {
        require(
            totalSupply() + _count <= MAX_DDC,
            "Exceeds maximum supply of Decadent Dogs Club"
        );
        require(
            _count > 0,
            "Minimum 1 Decadent Dog has to be minted per transaction"
        );
        if (msg.sender != owner()) {
            require(saleOpen, "Sale is not open yet");
            require(
                _count <= 3,
                "Maximum 3 Decadent Dogs Club can be minted per transaction"
            );
            require(
                msg.value >= price * _count,
                "Ether sent with this transaction is not correct"
            );
        }

        for (uint256 i = 0; i < _count; i++) {
            _mint(_to);
        }
    }

    function _mint(address _to) private {
        _tokenId.increment();
        uint256 tokenId = _tokenId.current();
        _safeMint(_to, tokenId);
        emit DecadentDogsClubMinted(tokenId);
    }

    function _baseURI() internal view virtual override returns (string memory) {
        return baseTokenURI;
    }
}
/// @author Hammad Ghazi
function walletOfOwner(address _owner)
    external
    view
    returns (uint256[] memory)
{
    uint256 tokenCount = balanceOf(_owner);

    uint256[] memory tokensId = new uint256[](tokenCount);
    for (uint256 i = 0; i < tokenCount; i++) {
        tokensId[i] = tokenOfOwnerByIndex(_owner, i);
    }

    return tokensId;
}

//Get token Ids of all tokens owned by _owner