contract TelestoDigikey is ERC1155, Ownable, ERC1155Burnable, ERC1155Supply {
    constructor() ERC1155("https://smol.mypinata.cloud/ipfs/QmU8zGGNBa8qfAqqry5xQrhB7t3ixfBUL3Uz6YV9R6XGcP/{id}.json") {
        setMintPrice(1,250000000000000000);
        setWhitelistMintPrice(1,200000000000000000);
        setMintPrice(2,250000000000000000);
        setWhitelistMintPrice(2,200000000000000000);
        setMintable(1,true);
        setMaximumSupply(1,1000);
        setMaximumSupply(2,1000);
    }

    mapping(address => bool) public whitelisted;
    mapping(address => uint) public minted;
    mapping(uint => uint) public mintPrices;
    mapping(uint => uint) public maximumSupply;
    mapping(uint => bool) public mintable;
    mapping(uint => uint) public whitelistMintPrices;
    uint public activeEdition = 1;
    uint public mintLimit = 5;
    
    function whitelistMembers(address[] memory addresses) public {
        for (uint i=0; i<addresses.length; i++) {
            whitelisted[addresses[i]] = true;
        }
    }

    function mintDigiKey() public payable {
        require(minted[msg.sender] < mintLimit,"Mint limit reached.");
        mintItem(activeEdition);
        minted[msg.sender]=minted[msg.sender] + 1;
    }

    function activeMintPrice() public view returns (uint){
        return mintPrices[activeEdition];
    }


    function mintPrice(address wallet,uint tokenId) public view returns (uint){
        bool isWhitelisted = whitelisted[wallet];
        if(isWhitelisted){
            return whitelistMintPrices[tokenId];
        }else{
            return mintPrices[tokenId];
        }
    }
    
    function name() public pure  returns (string memory){
        return "Telesto Digikey";
    }
    function symbol() public pure  returns (string memory){
        return "DIGIKEY";
    }
    

    function mintItem(uint tokenId) internal {
        require(totalSupply(tokenId) < maximumSupply[tokenId]);
        require(mintable[tokenId]);
        if(whitelisted[msg.sender]){
            uint discountedMintPrice = whitelistMintPrices[tokenId];
            require(msg.value >= discountedMintPrice,"increase value to mint");
        }else{
            uint publicMintPrice = mintPrices[tokenId];
            require(msg.value >= publicMintPrice,"increase value to mint");
        }
        _mint(msg.sender,tokenId,1,"");
    }


    function setURI(string memory newuri) public onlyOwner {
        _setURI(newuri);
    }
    function setWhitelistMintPrice(uint tokenId,uint whitelistMintPrice) public onlyOwner {
        whitelistMintPrices[tokenId]=whitelistMintPrice;
    }
    
    function setMintPrice(uint tokenId,uint publicMintPrice) public onlyOwner {
        mintPrices[tokenId] = publicMintPrice;
    }
    
    function setMaximumSupply(uint tokenId,uint amount) public onlyOwner {
        maximumSupply[tokenId]=amount;
    }
    function setActiveEdition(uint tokenId) public onlyOwner {
        activeEdition = tokenId;
    }
    function setMintable(uint tokenId,bool canMint) public onlyOwner {
        mintable[tokenId]=canMint;
    }

    function mint(address account, uint256 id, uint256 amount, bytes memory data)
        public
        onlyOwner
    {
        _mint(account, id, amount, data);
    }

    function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
        public
        onlyOwner
    {
        _mintBatch(to, ids, amounts, data);
    }

    // The following functions are overrides required by Solidity.

    function _beforeTokenTransfer(address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
        internal
        override(ERC1155, ERC1155Supply)
    {
        super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
    }

    function withdraw() public onlyOwner {
        require(address(this).balance > 0);
        require(address(msg.sender) == owner());
        payable(msg.sender).transfer(address(this).balance);
    }
}
function _beforeTokenTransfer(address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
    internal
    override(ERC1155, ERC1155Supply)
{
    super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
}

// The following functions are overrides required by Solidity.