contract DyNifty_10_TML is ERC721, Ownable {
    
    using SafeERC20 for IERC20;
    IERC20 public _token;

    string private _state1_IPFS;
    string private _state2_IPFS;
    uint256 private _current_state;


    /*
    The contract is initialized to be able to receive and handle a specific ERC20 token. In this case, wBTC (Wrapped BTC, 1:1 pegged to BTC)
    Do not send any other ERC20 token as it will be locked forever into the contract. 
    */
    constructor(IERC20 token) ERC721("Satoshi's Coin", "byTML") public {
        _token = token;
        _current_state = 0;
    }

    /*
    Internal function to change the state from 1 to 2. Used only by the burn function.
    */
    function _updateState() internal {
       _current_state = 2;
       _setTokenURI(1, _state2_IPFS); 
    }
    


    /*
    The mintNFT function allows the contract owner to mint one and only one NFT token of this kind. This guarantees a 1/1 only piece.
    The NFT can exists in 2 different states, representing the Bitcoin locked state and the "burned" un-owned token.
    */
    function mintNFT(address collector, string memory base_URI,  string memory state1_URI, string memory state2_URI) onlyOwner public returns (uint256) {
        require(_current_state == 0, "ERC721: Cannot mint more than one token");
    
        uint256 newItemId = 1;
        _current_state = 1;

        _state1_IPFS = state1_URI;
        _state2_IPFS = state2_URI;

        _mint(collector, newItemId);
        _setBaseURI(base_URI);
        _setTokenURI(newItemId, state1_URI);

        return newItemId;
    }

    /*
    The burn function can only be triggered by the owner of the token or an account approved by the current owner. Approved accounts will be reset at every change of ownership.
    This is a different take on "burning" - the NFT token will get transferred to the contract address itself, and locked in forever in its second state.
    */
    function burn() public {
        require(_isApprovedOrOwner(msg.sender, 1), "ERC721: caller is not owner nor approved");


        address current_owner = ownerOf(1);
        uint256 tot_balance = _token.balanceOf(address(this));

        _token.safeTransfer(current_owner, tot_balance); 
        _updateState();
        transferFrom(current_owner, address(this), 1);

       
    }





}
//import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.2.0/contracts/token/ERC721/ERC721.sol";
//import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.2.0/contracts/access/Ownable.sol";
//import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.2.0/contracts/token/ERC20/IERC20.sol";
//import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.2.0/contracts/token/ERC20/SafeERC20.sol";
//wbtc=0x2260fac5e5542a773aa44fbcfedf7c193bc2c599
function mintNFT(address collector, string memory base_URI,  string memory state1_URI, string memory state2_URI) onlyOwner public returns (uint256) {
    require(_current_state == 0, "ERC721: Cannot mint more than one token");
    
    uint256 newItemId = 1;
    _current_state = 1;

    _state1_IPFS = state1_URI;
    _state2_IPFS = state2_URI;

    _mint(collector, newItemId);
    _setBaseURI(base_URI);
    _setTokenURI(newItemId, state1_URI);

    return newItemId;
}

/*
 The mintNFT function allows the contract owner to mint one and only one NFT token of this kind. This guarantees a 1/1 only piece.
 The NFT can exists in 2 different states, representing the Bitcoin locked state and the "burned" un-owned token.
 */