contract LogicBots is ERC721 {

  using Counters for Counters.Counter;
  Counters.Counter private _tokenIds;

  address payable public owner;
  uint256 public price = 250000000000000000;

  constructor(bytes32[] memory assetsForSale) payable public ERC721("LogicBots", "LGB") {
    owner = payable(msg.sender);
    _setBaseURI("https://ipfs.io/ipfs/");
    for(uint256 i=0;i<assetsForSale.length;i++){
      forSale[assetsForSale[i]] = true;
    }
  }

    modifier onlyOwner(){
    require (msg.sender == owner,"Not Owner");
    _;
  }

  function withdraw(uint amount) public onlyOwner returns(bool) {
        require(amount <= address(this).balance, "Not that much in the contract");
        owner.transfer(amount);
        return true;

    }
    /*
    function getOwner() public returns(address){
      return owner;
    }
    */

  function getContractBalance() public view returns(uint){
      return  address(this).balance;
  }

  //this marks an item in IPFS as "forsale"
  mapping (bytes32 => bool) public forSale;
  //this lets you look up a token by the uri (assuming there is only one of each uri for now)
  mapping(bytes32 => uint256) public uriToTokenId;

  function mintItem(string memory tokenURI)
      public
      payable
      returns(uint256)
  {
      require(msg.value >= price, "price too low");
      
      bytes32 uriHash = keccak256(abi.encodePacked(tokenURI));

      //make sure they are only minting something that is marked "forsale"
      require(forSale[uriHash],"Already sold!!!");
      forSale[uriHash]=false;

      _tokenIds.increment();
 
      uint256 id = _tokenIds.current();
      _mint(msg.sender, id);
      _setTokenURI(id, tokenURI);

      uriToTokenId[uriHash] = id;

      return id;
  }
}
//SPDX-License-Identifier: MIT
//import "hardhat/console.sol";
//import "@openzeppelin/contracts/access/Ownable.sol";
//learn more: https://docs.openzeppelin.com/contracts/3.x/erc721
// GET LISTED ON OPENSEA: https://testnets.opensea.io/get-listed/step-two
function getContractBalance() public view returns(uint){
    return  address(this).balance;
}

/*
 function getOwner() public returns(address){
 return owner;
 }
 */