contract RHOVITContract is ERC1155, Ownable {

    bytes4 constant private INTERFACE_SIGNATURE_URI = 0x0e89341c;

     // Token name
    string private _contractName = 'RHOVIT';

    // Token symbol
    string private _symbol = 'O';

    // Base URI
    string private _baseURI = 'https://rhovit.com/api/items/';

    // Total Supplies
    mapping(uint256 => uint256) private _totalSupplies;

    // A nonce to ensure we have a unique id each time we mint.
    uint256 public nonce;

        /**
        @dev Must emit on creation
        The `_name` Name at creation gives some human context to what this token is in the blockchain
        The `_id` Id of token.
    */
    event CreationName(string _value, uint256 indexed _id);

    event Update(string _value, uint256 indexed _id);

    function supportsInterface(bytes4 _interfaceId)
    public
    view
    returns (bool) {
        if (_interfaceId == INTERFACE_SIGNATURE_URI) {
            return true;
        } else {
            return super.supportsInterface(_interfaceId);
        }
    }

    // Creates a new token type and assings _initialSupply to minter
    function create(uint256 _initialSupply, address _to, string calldata _name) external onlyOwner returns (uint256 _id) {

        _id = _create(_initialSupply, _to, _name); 

    }

    // Creates a new token type and assings _initialSupply to minter
    function _create(uint256 _initialSupply, address _to, string memory _name) internal returns (uint256 _id) {

        _id = ++nonce;
        balances[_id][_to] = _initialSupply;
        _totalSupplies[_id] = _initialSupply;

        // Transfer event with mint semantic
        emit TransferSingle(msg.sender, address(0x0), _to, _id, _initialSupply);

        emit URI(string(abi.encodePacked(baseTokenURI(),Strings.uint2str(_id))), _id);

        if (bytes(_name).length > 0)
            emit CreationName(_name, _id);

    }

    // Batch mint tokens. Assign directly to _to[].
    function batchCreate(uint256[] calldata _initialSupplies, address[] calldata _to, string calldata _name) external onlyOwner {
        
        for (uint256 i = 0; i < _to.length; ++i) {
            _create(_initialSupplies[i], _to[i], _name); 
        }

    }

    function setBaseURI(string calldata uri) external onlyOwner {
        _baseURI = uri;
    }

    function update(string calldata _update, uint256 _id) external onlyOwner {
        emit Update(_update, _id);
    }

    function baseTokenURI() public view returns (string memory) {
        return _baseURI;
    }

    function uri(uint256 _id) external view returns (string memory) {
        
        assert(_totalSupplies[_id] != 0);

        return string(abi.encodePacked(baseTokenURI(),Strings.uint2str(_id)));
    }

    function tokenURI(uint256 _id) external view returns (string memory) {
        
        assert(_totalSupplies[_id] != 0);

        return string(abi.encodePacked(baseTokenURI(),Strings.uint2str(_id)));
    }

    /**
     * @dev Gets the token name.
     * @return string representing the token name
     */
    function name() external view returns (string memory) {
        return _contractName;
    }

    /**
     * @dev Gets the token symbol.
     * @return string representing the token symbol
     */
    function symbol() external view returns (string memory) {
        return _symbol;
    }

    /// @notice Returns the total token supply.
    /// @dev Throws if '_tokenType' is not a valid SFT
    /// @param _id The type of SFT to get the totalSupply of. Must be less than the return value of totalTokenTypes
    /// @return The total supply of the given SFT
    function totalSupply(uint256 _id) external view returns (uint256) {
        return _totalSupplies[_id];
    }

    /// @notice Returns the total number of token types for this contract
    /// @dev Can possibly be zero
    /// @return The total number of token types
    function totalTokenTypes() external view returns (uint256) {
        return nonce;
    }
}
/**
 @dev Mintable form of ERC1155
 Shows how easy it is to mint new items.
 */
function totalTokenTypes() external view returns (uint256) {
    return nonce;
}

/// @notice Returns the total number of token types for this contract
/// @dev Can possibly be zero
/// @return The total number of token types