contract Degenz_Fud is ERC721, Ownable {
    using SafeMath for uint256;

    string public FUD_PROVENANCE = "";

    uint256 public constant MAX_FUDZ = 2538;

    bool public mintIsActive = false;

    mapping(address => uint256) private claimableFudBalance;


    constructor(string memory name, string memory symbol) ERC721(name, symbol) {
    }

    function withdraw() public onlyOwner {
        uint balance = address(this).balance;
        msg.sender.transfer(balance);
    }

    function whitelist(address[] calldata wallets, uint256[] calldata balances) external onlyOwner {
        require(wallets.length == balances.length,"Wallets and balances arrays should be of same length");
        for(uint256 i=0; i<wallets.length; i++){
            claimableFudBalance[wallets[i]] = balances[i];
        }
    }

    function whitelistedBalance(address wallet) external view returns(uint256) {
        return claimableFudBalance[wallet];
    } 

    /*     
    * Set provenance once it's calculated
    */
    function setProvenanceHash(string memory provenanceHash) public onlyOwner {
        FUD_PROVENANCE = provenanceHash;
    }

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

    /*
    * Pause sale if active, make active if paused
    */
    function flipMintState() public onlyOwner {
        mintIsActive = !mintIsActive;
    }

    /**
    * Mints FUD
    */
    function mintFUD(uint256 noOfTokens) public {
        require(mintIsActive, "FUDZ minting is not active");
        require(claimableFudBalance[msg.sender] > 0, "You have Zero claimable FUDZ");
        require(noOfTokens <= claimableFudBalance[msg.sender], "Trying to mint more than claimable FUDZ");
        require(totalSupply()+noOfTokens <= MAX_FUDZ, "mint will exceed max supply");
        
        for(uint256 i=0; i<noOfTokens; i++) {
            if (totalSupply() < MAX_FUDZ) {
                _safeMint(msg.sender, totalSupply());
            }
        }
        claimableFudBalance[msg.sender] = claimableFudBalance[msg.sender].sub(noOfTokens);
    }
}
/**
 * @title Degenz FUD contract
 * @dev Extends ERC721 Non-Fungible Token Standard basic implementation
 */
function flipMintState() public onlyOwner {
    mintIsActive = !mintIsActive;
}

/*
 * Pause sale if active, make active if paused
 */