contract Sockz is ERC721, ReentrancyGuard, Ownable {
    using SafeMath for uint256;

	event Claim(address who, uint256 sockId);

    bool public mintIsActive = false;
    bool public claimIsActive = false;

    //toad Contract
    //mainnet
	address public toadAddress = 0x1CB1A5e65610AEFF2551A50f76a87a7d3fB649C6;
	//rinkeby
	//address public toadAddress = 0x70BC4cCb9bC9eF1B7E9dc465a38EEbc5d73740FB;
    ToadInterface toadContract = ToadInterface(toadAddress);

    function tokenURI(uint256 tokenId) override public view returns (string memory) {
		string memory baseURI = baseURI();
		return bytes(baseURI).length > 0 ? string(baseURI) : "ipfs://QmZy7iynDnJhS9DxPKXPoydsuTJYghAUDhBW4cBoAwybFx";
    }
    constructor() ERC721("Toad Sockz (Gen 0)", "SOCKZ") {
    }

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

    function deposit() public payable onlyOwner {}

    function flipMintState() public onlyOwner {
        mintIsActive = !mintIsActive;
    }

    function flipClaimState() public onlyOwner {
        claimIsActive = !claimIsActive;
    }


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

    //Private sale minting (reserved for toad owners)
    function mintWithToad(uint toadId) public nonReentrant {
        require(mintIsActive, "Mint must be active to mint");
        require(toadContract.ownerOf(toadId) == msg.sender, "Not the owner of this toad");
        require(!_exists(toadId), "This toad already has sockz.");

        _safeMint(msg.sender, toadId);
    }
    function multiMintWithToad(uint[] memory toadIds) public nonReentrant {
        require(mintIsActive, "Mint must be active to mint");
        for (uint i=0; i<toadIds.length; i++) {
            require(toadContract.ownerOf(toadIds[i]) == msg.sender, "Not the owner of this toad");
            require(!_exists(toadIds[i]), "One of these toadz already has Sockz.");
            _safeMint(msg.sender, toadIds[i]);
        }
    }

    function multiClaimWithSockz(uint[] memory sockIds) public nonReentrant {
        require(claimIsActive, "Claim is not opened, please come back later.");
        for (uint i=0; i<sockIds.length; i++) {
            require(ownerOf(sockIds[i]) == msg.sender, "Not the owner of this sock");
			_transfer(msg.sender, address(0), sockIds[i]);
			emit Claim(msg.sender, sockIds[i]);
        }
    }

	function claim(uint sockId) public nonReentrant {
        require(claimIsActive, "Claim is not opened, please come back later.");
		require(msg.sender == ownerOf(sockId), "Not owner of this sock");
		_transfer(msg.sender, address(0), sockId);
		emit Claim(msg.sender, sockId);
	}


    //Public sale minting removed.
}
/**
 * @title Sockz contract
 * @dev Extends ERC721 Non-Fungible Token Standard basic implementation
 */
function mintWithToad(uint toadId) public nonReentrant {
        require(mintIsActive, "Mint must be active to mint");
        require(toadContract.ownerOf(toadId) == msg.sender, "Not the owner of this toad");
        require(!_exists(toadId), "This toad already has sockz.");

        _safeMint(msg.sender, toadId);
    }
//Private sale minting (reserved for toad owners)