contract LootTunes is ERC721Enumerable, ReentrancyGuard, Ownable {
    using SafeMath for uint256;

    string public PROVENANCE = "";
    uint256 public publicPrice = 0.01 ether;
    string public baseURI = "https://loottunes.fun/api/token/";

    // number of tokens sold to the public
    uint256 public numPublicSold = 0;

    //Loot Contract
    address public lootAddress = 0xFF9C1b15B16263C61d017ee9F65C50e4AE0113D7;
    LootInterface lootContract = LootInterface(lootAddress);

    constructor() ERC721("Tunes", "LOOTTUNE") {
    }

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

    function deposit() public payable onlyOwner {}

    function setPublicPrice(uint256 newPrice) public onlyOwner {
        publicPrice = newPrice;
    }

    function _baseURI() internal view virtual override returns (string memory) {
        return baseURI;
    }

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

    function setProvenance(string memory prov) public onlyOwner {
        PROVENANCE = prov;
    }

    //Private sale minting (reserved for Loot owners)
    function mintWithLoot(uint lootId) public payable nonReentrant {
        require(lootId > 0 && lootId <= 8000, "Not a valid loot ID. Did you mean to use the regular mint function?");
        require(lootContract.ownerOf(lootId) == msg.sender, "Not this loot's owner");

        _safeMint(msg.sender, lootId);
    }

    function multiMintWithLoot(uint256[] memory lootIds) public payable nonReentrant {
        for (uint256 i = 0; i < lootIds.length; i++) {
            require(lootContract.ownerOf(lootIds[i]) == msg.sender, "Not this loot's owner");
            _safeMint(_msgSender(), lootIds[i]);
        }
    }

    //Public sale minting
    function mint(uint lootId) public payable nonReentrant {
        require(publicPrice <= msg.value, "Not enough ether sent");
        require(lootId > 8000 && lootId <= 12000, "Token ID invalid (only IDs 8000 to 12000 are mintable with this function)");
        _safeMint(msg.sender, lootId);
        numPublicSold += 1;
        updatePrice();
    }

    function multiMint(uint256[] memory lootIds) public payable nonReentrant {
        require(lootIds.length <= 10, "You may only mint 10 Tunes or less per transaction");
        require((publicPrice * lootIds.length) <= msg.value, "Ether value sent is not correct");
        for (uint256 i = 0; i < lootIds.length; i++) {
            require(lootIds[i] > 8000 && lootIds[i] < 12000, "Token ID invalid (only IDs 8000 to 12000 are mintable with this function)");
            _safeMint(msg.sender, lootIds[i]);
            numPublicSold += 1;
            updatePrice();
        }
    }

    function updatePrice() internal {
        if (numPublicSold == 100) {
            publicPrice = 0.03 ether;
        } else if (numPublicSold == 1000) {
            publicPrice = 0.05 ether;
        }
    }
}
function mint(uint lootId) public payable nonReentrant {
    require(publicPrice <= msg.value, "Not enough ether sent");
    require(lootId > 8000 && lootId <= 12000, "Token ID invalid (only IDs 8000 to 12000 are mintable with this function)");
    _safeMint(msg.sender, lootId);
    numPublicSold += 1;
    updatePrice();
}

//Public sale minting