contract FootballerOwnership is FootballerBase, ERC721 {
  /// @notice Name and symbol of the non fungible token, as defined in ERC721.
  string public constant name = "CyptoWorldCup";
  string public constant symbol = "CWC";


  function implementsERC721() public pure returns (bool) {
    return true;
  }

  //判断一个给定的地址是不是现在某个球员的拥有者
  function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
    return footballerToOwner[_tokenId] == _claimant;
  }

  //判断一个给定的地址现在对于某个球员 是不是有 transferApproval
  function _approvedFor(address _claimant, uint256 _tokenId) internal view returns (bool) {
    return footballerToApproved[_tokenId] == _claimant;
  }

  //给某地址的用户 对 球员有transfer的权利
  function _approve(uint256 _tokenId, address _approved) internal {
      footballerToApproved[_tokenId] = _approved;
  }

  //返回 owner 拥有的球员数
  function balanceOf(address _owner) public view returns (uint256 count) {
    return ownershipTokenCount[_owner];
  }

  //转移 球员 给 另一个地址
  function transfer(address _to, uint256 _tokenId) public whenNotPaused {
    require(_to != address(0));
    require(_to != address(this));
    //只能send自己的球员
    require(_owns(msg.sender, _tokenId));
    //重新分配所有权，清除待批准 approvals ，发出转移事件
    _transfer(msg.sender, _to, _tokenId);
  }

  //授予另一个地址通过transferFrom（）转移特定球员的权利。
  function approve(address _to, uint256 _tokenId) external whenNotPaused {
    //只有球员的拥有者才有资格决定要把这个权利给谁
    require(_owns(msg.sender, _tokenId));
    _approve(_tokenId, _to);
    emit Approval(msg.sender, _to, _tokenId);
  }

  //转让由另一个地址所拥有的球员，该地址之前已经获得所有者的转让批准
  function transferFrom(address _from, address _to, uint256 _tokenId) external whenNotPaused {
    require(_to != address(0));
    //不允许转让本合同以防止意外滥用。
    // 合约不应该拥有任何球员（除非 在创建球星之后并且在拍卖之前 非常短）。
    require(_to != address(this));
    require(_approvedFor(msg.sender, _tokenId));
    require(_owns(_from, _tokenId));
    //该函数定义在FootballerBase
    _transfer(_from, _to, _tokenId);
  }

  //返回现在一共有多少（球员+球星）
  function totalSupply() public view returns (uint) {
    return footballers.length;
  }

  //返回该特定球员的拥有者的地址
  function ownerOf(uint256 _tokenId) external view returns (address owner) {
    owner = footballerToOwner[_tokenId];
    require(owner != address(0));
  }

  //返回该地址的用户拥有的球员的id
  function tokensOfOwner(address _owner) external view returns(uint256[] ownerTokens) {
    uint256 tokenCount = balanceOf(_owner);
    if(tokenCount == 0) {
      return new uint256[](0);
    } else {
      uint256[] memory result = new uint256[](tokenCount);
      uint256 totalpalyers = totalSupply();
      uint256 resultIndex = 0;
      uint256 footballerId;
      for (footballerId = 0; footballerId < totalpalyers; footballerId++) {
        if(footballerToOwner[footballerId] == _owner) {
          result[resultIndex] = footballerId;
          resultIndex++;
        }
      }
      return result;
    }
  }
}
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
  return footballerToOwner[_tokenId] == _claimant;
}

//判断一个给定的地址是不是现在某个球员的拥有者