contract RtistiqBase is Ownable, Pausable {

    using SafeMath for uint256;
    using Address for address;

    // address private owner;

    //address of the token contract
    address private tokenContract;

    using Counters for Counters.Counter;
    Counters.Counter private tokenIds;

    struct art {
        address owner;
        string ipfsMetadataHash;
    }

    mapping(uint256 => art) private arts;

    mapping(bytes32 => bool) private rfids;
 
    // Mapping from token ID to approved address
    mapping (uint256 => address) private tokenApprovals;

    bool public isRtistiqBase = true;
   
    modifier onlyTokenContract() {
        require(msg.sender == tokenContract, "Sender not allowed to call this function");
        _;
    }

    function setTokenContract(address _currentTokenContract) public onlyOwner {
        tokenContract = _currentTokenContract;
    }

    function getTokenContract() public view returns (address) {
        return tokenContract;
    }
    
    function rfidExists(bytes32 _rfid) public view returns (bool) {
       return rfids[_rfid];
    }

    function tokenExists(uint256 _tokenId) public view returns (bool) {
        if (arts[_tokenId].owner!=address(0)) {
            return true;
        }
        else {
            return false;
        }
    }

    function getTokenOwnerOf(uint256 _tokenId) public view returns (address) {
        return arts[_tokenId].owner;
    }

    function getTokenURI(uint256 _tokenId) public view returns (string memory) {
        return arts[_tokenId].ipfsMetadataHash;
    }

    function mintToken(address _to, 
        bytes32 _rfid, 
        string memory _tokenURI
    ) public onlyTokenContract whenNotPaused returns (uint256) {
        tokenIds.increment(); 
        uint256 tokenId =  tokenIds.current();     
        arts[tokenId].ipfsMetadataHash = _tokenURI;
        arts[tokenId].owner = _to;
        rfids[_rfid] = true;
        return tokenId;
    } 

    function burnToken(uint256 _tokenId) public onlyTokenContract whenNotPaused {
        setTokenApprovals(address(0), _tokenId);
        arts[_tokenId].ipfsMetadataHash = '';
        arts[_tokenId].owner = address(0);
        // rfids[_rfid] = true;
    }
    
    function transferToken(address _to, uint256 _tokenId) public onlyTokenContract whenNotPaused {
        setTokenApprovals(address(0), _tokenId);
        arts[_tokenId].owner = _to;
    }

    function updateTokenMetadata(uint256 _tokenId, string memory _tokenURI) public onlyTokenContract whenNotPaused {
        arts[_tokenId].ipfsMetadataHash = _tokenURI;
    }

    function setTokenApprovals(address _to, uint256 _tokenId) public onlyTokenContract whenNotPaused returns (address) {
        return tokenApprovals[_tokenId] = _to;
    }

    function getTokenApprovals(uint256 _tokenId) public view returns (address) {
        require(tokenExists(_tokenId), "Token does not exists");
        return tokenApprovals[_tokenId];
    }

    /**
    * @dev called by the owner to pause, triggers stopped state
    */
    function pause() onlyOwner whenNotPaused public {
        _pause();
    }

    /**
    * @dev called by the owner to unpause, returns to normal state
    */
    function unpause() onlyOwner whenPaused public {
        _unpause();
    }

}
function pause() onlyOwner whenNotPaused public {
    _pause();
}

/**
 * @dev called by the owner to pause, triggers stopped state
 */