contract LSNFT is ERC721Token {
  
  /*** EVENTS ***/

  /// @dev The Created event is fired whenever a new collectible comes into existence.
  event Created(address owner, uint256 tokenId);
  
  /*** DATATYPES ***/
  
  struct NFT {
    // The sequence of potential attributes a Collectible has and can provide in creation events. Used in Creation logic to spwan new Cryptos
    uint256 attributes;

    // Current Game Card identifier
    uint256 currentGameCardId;

    // MLB Game Identifier (if asset generated as a game reward)
    uint256 mlbGameId;

    // player orverride identifier
    uint256 playerOverrideId;

    // official MLB Player ID
    uint256 mlbPlayerId;

    // earnedBy : In some instances we may want to retroactively write which MLB player triggered
    // the event that created a Legendary Trophy. This optional field should be able to be written
    // to after generation if we determine an event was newsworthy enough
    uint256 earnedBy;
    
    // asset metadata
    uint256 assetDetails;
    
    // Attach/Detach Flag
    uint256 isAttached;
  }

  NFT[] allNFTs;

  function isLSNFT() public view returns (bool) {
    return true;
  }

  /// For creating NFT
  function _createNFT (
    uint256[5] _nftData,
    address _owner,
    uint256 _isAttached)
    internal
    returns(uint256) {

    NFT memory _lsnftObj = NFT({
        attributes : _nftData[1],
        currentGameCardId : 0,
        mlbGameId : _nftData[2],
        playerOverrideId : _nftData[3],
        assetDetails: _nftData[0],
        isAttached: _isAttached,
        mlbPlayerId: _nftData[4],
        earnedBy: 0
    });

    uint256 newLSNFTId = allNFTs.push(_lsnftObj) - 1;

    _mint(_owner, newLSNFTId);
    
    // Created event
    emit Created(_owner, newLSNFTId);

    return newLSNFTId;
  }

  /// @dev Gets attributes of NFT  
  function _getAttributesOfToken(uint256 _tokenId) internal returns(NFT) {
    NFT storage lsnftObj = allNFTs[_tokenId];  
    return lsnftObj;
  }

  function _approveForSale(address _owner, address _to, uint256 _tokenId) internal {
    address owner = ownerOf(_tokenId);
    require (_to != owner);
    require (_owner == owner || isApprovedForAll(owner, _owner));

    if (getApproved(_tokenId) != address(0) || _to != address(0)) {
        tokenApprovals[_tokenId] = _to;
        emit Approval(_owner, _to, _tokenId);
    }
  }
}
/* Lucid Sight, Inc. ERC-721 Collectibles. 
 * @title LSNFT - Lucid Sight, Inc. Non-Fungible Token
 * @author Fazri Zubair & Farhan Khwaja (Lucid Sight, Inc.)
 */
function _createNFT (
  uint256[5] _nftData,
  address _owner,
  uint256 _isAttached)
  internal
  returns(uint256) {

  NFT memory _lsnftObj = NFT({
      attributes : _nftData[1],
      currentGameCardId : 0,
      mlbGameId : _nftData[2],
      playerOverrideId : _nftData[3],
      assetDetails: _nftData[0],
      isAttached: _isAttached,
      mlbPlayerId: _nftData[4],
      earnedBy: 0
  });

  uint256 newLSNFTId = allNFTs.push(_lsnftObj) - 1;

  _mint(_owner, newLSNFTId);
    
  // Created event
  emit Created(_owner, newLSNFTId);

  return newLSNFTId;
}

/// For creating NFT