contract YubbaWorld is ERC1155, Ownable, PaymentSplitter {
    //@dev Attributes for NFT configuration
    uint256 internal tokenId;
    uint256 public cost = 0.05 ether;
    uint256 public maxSupply = 10000;
    uint256 public maxMintAmount = 5;
    mapping(address => uint256) public whitelist;
    bool public paused;
    bool public consumables;
    uint256 public constant healthPotion = 99999;
    uint256 public constant GOLD = 99998;

    // @dev inner attributes of the contract

    /**
     * @dev Create an instance of YubbaWorld contract
     */
    constructor(
        string memory _baseURI
    ) ERC1155(_baseURI) {
        tokenId = 0;
    }

    /**
     * @dev Mint edition to a wallet
     * @param _to wallet receiving the edition(s).
     * @param _mintAmount number of editions to mint.
     */
    function mint(address _to, uint256 _mintAmount, uint256 _tokenId) public payable {
        require(!paused, "Sales are paused");
        require(_mintAmount <= maxMintAmount, "Max amount exceeded");
        require(
            tokenId + _mintAmount <= maxSupply,
            "Not enough mintable editions !"
        );
        
        if(whitelist[_to] < _mintAmount)
            require(
                msg.value >= cost * _mintAmount,
                "Insufficient transaction amount."
            );
        else
            whitelist[_to] -= _mintAmount;
        
        if(_tokenId > maxSupply){
            require(consumables == true, "consumables not mintable yet");
            _mint(_to, _tokenId, _mintAmount, "");
        }
        else 
            for (uint256 i = 0; i < _mintAmount; i++) {
                tokenId++;
                _mint(_to, tokenId, 1, "");
            }
    }

    // /**
    //  * @dev Mint edition to a wallet
    //  * @param _to wallet receiving the edition(s).
    //  * @param _mintAmount number of editions to mint.
    //  */
    // function mintConsumables(
    //     address _to,
    //     uint256 _mintAmount,
    //     uint256 _id
    // ) public payable {
    //     require(!consumables, "Sales are paused");
    //     require(_id > tokenId);
    //     require(
    //         msg.value >= cost * _mintAmount,
    //         "Insufficient transaction amount."
    //     );
    //     _mint(_to, _id, _mintAmount, "");
    // }

    /**
     * @dev change cost of NFT
     * @param _newCost new cost of each edition
     */
    function setCost(uint256 _newCost) public onlyOwner {
        cost = _newCost;
    }

    /**
     * @dev restrict max mintable amount of edition at a time
     * @param _newmaxMintAmount new max mintable amount
     */
    function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
        maxMintAmount = _newmaxMintAmount;
    }

    /**
     * @dev restrict max mintable amount of edition at a time
     * @param _nexMaxSupply new max supply
     */
    function setmaxSupply(uint256 _nexMaxSupply) public onlyOwner {
        maxSupply = _nexMaxSupply;
    }
    
    /**
     * @dev set uri
     * @param _newURI new URI
     */
    function setURI(string memory _newURI) public onlyOwner {
        _setURI(_newURI);
    }

    /**
     * @dev Disable minting process
     */
    function pause() public onlyOwner {
        paused = !paused;
    }

    /**
     * @dev Disable minting process
     */
    function pauseConsumables() public onlyOwner {
        consumables = !consumables;
    }
    /**
     * @dev Add user to white list
     * @param _user Users wallet to whitelist
     */
    function whitelistUserBatch(
        address[] memory _user,
        uint256[] memory _amount
    ) public onlyOwner {
        require(_user.length == _amount.length);
        for (uint256 i = 0; i < _user.length; i++)
            whitelist[_user[i]] = _amount[i];
    }
    
     /**
     * @dev Destroys `amount` tokens of token type `id` from `from`
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `from` must have at least `amount` tokens of token type `id`.
     */
    function burn(
        uint256 id,
        uint256 amount)
        public {
            _burn(msg.sender, id, amount);
        }
}
/**
 * @dev contract module which defines YubbaWorld NFT Collection
 * and all the interactions it uses
 */
function setURI(string memory _newURI) public onlyOwner {
    _setURI(_newURI);
}

/**
 * @dev set uri
 * @param _newURI new URI
 */