contract GoblinGoons is Context, ERC721Enumerable, ERC721Burnable, Ownable {
    using Counters for Counters.Counter;

    Counters.Counter private _tokenIdTracker;

    string private _baseTokenURI;
    
    address CobbleAddress = 0xE0666cAC0C2267209Ba3Da4Db00c03315Fe64fA8;
    address DarkoAddress = 0x95270f71252AF1F92E54c777237091F9382Ca5D8;
    address MattAddress = 0xd17EdAE5256Ba32A8b34DD428Bcc625B704Ad104;
    
    
    uint private constant maxGoblins = 8500;
    uint private constant mintPrice = 30000000000000000;
    bool private paused = true;
    
    event CreateGoblin(uint indexed id, uint coins, uint attributeSeed);
    
    
    mapping(uint => uint) private goldCoins;
    uint public totalGoldCoins = 0;

    constructor() ERC721("Goblin Goons", "GOGS") {
        _baseTokenURI = "https://goblingoonslair.com/goblin/";
    }

    function _baseURI() internal view virtual override returns (string memory) {
        return _baseTokenURI;
    }
    
    function setBaseURI(string memory baseURI) external onlyOwner {
        _baseTokenURI = baseURI;
    }
    

    function mint(uint amount) public payable {
        require(!paused || msg.sender == owner());
        require(amount > 0 && amount < 11, "You can only mint between 1 and 10 Goblins.");
        require(msg.value == mintPrice*amount || msg.sender == owner(), "It costs 0.03 eth to mint a Goblin.");
        require(totalSupply() + amount < maxGoblins, "There can only be 8500 Goblins!");
        for(uint i = 0; i < amount; i++) {
            _tokenIdTracker.increment();
            mintGoblin(_tokenIdTracker.current());
        }
    }
    
    function mintGoblin(uint id) private {
        _mint(msg.sender, id);
        
        uint randomNumber =  uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp, totalSupply())));
        
        uint randomCoins;
        if(randomNumber % 100 < 75) {randomCoins = 1;}
        else if(randomNumber % 100 < 95) {randomCoins = 2;}
        else {randomCoins = 3;}
        
        goldCoins[id] = randomCoins;
        totalGoldCoins = totalGoldCoins + randomCoins;
        emit CreateGoblin(id, randomCoins, randomNumber);
    }
    
    function getGoblinsCoins(uint id) public view returns(uint) {
        return goldCoins[id];
    }
    
    function goldBalance(address person) public view returns(uint) {
        uint total = 0;
        for(uint i = 0; i < balanceOf(person); i++) {
            total = total + getGoblinsCoins(tokenOfOwnerByIndex(person, i));
        }
        return total;
    }

    function pause() public virtual onlyOwner {
        paused = true;
    }

    function unpause() public virtual onlyOwner {
        paused = false;
    }
    
    function withdraw() external onlyOwner {
        uint balance = address(this).balance;
        payable(CobbleAddress).transfer((balance*3)/20);
        payable(DarkoAddress).transfer(balance/10);
        payable(MattAddress).transfer(balance/25);
        payable(msg.sender).transfer(address(this).balance);
    }

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

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, ERC721Enumerable) returns (bool) {
        return super.supportsInterface(interfaceId);
    }
}
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, ERC721Enumerable) returns (bool) {
    return super.supportsInterface(interfaceId);
}

/**
 * @dev See {IERC165-supportsInterface}.
 */