local this = {}

function this:init()
  this.super.init(self)
  self.data = {
    friendList = {},
    friendApplicationList = {},
    recentTeamList = {},
    blackList = {},
    baseInfoList = {},
    playerDetailInfoList = {}
  }
end

function this:getFriendList()
  return self.data.friendList
end

function this:getFriendApplicationList()
  return self.data.friendApplicationList
end

function this:getRecentTeamList()
  return self.data.recentTeamList
end

function this:getBlackList()
  return self.data.blackList
end

function this:getBaseInfoList()
  return self.data.baseInfoList
end

function this:getPlayerDetailInfoList()
  return self.data.playerDetailInfoList
end

function this:getPlayerItem(playerList, playerUid, isCreate)
  local entity = playerList[playerUid]
  if entity == nil and isCreate then
    entity = require(L_R.store .. "friend.data.playerItem").new()
    playerList[playerUid] = entity
    entity.playerUid = playerUid
  end
  return entity
end

function this:getPlayerBaseInfo(playerUid, isCreate)
  if playerUid == L_PlayerStore:getPlayerId() then
    return L_PlayerStore:getPlayerBaseInfo()
  end
  local baseInfoList = self:getBaseInfoList()
  local entity = baseInfoList[playerUid]
  if entity == nil and isCreate then
    entity = require(L_R.store .. "player.data.playerBaseInfo").new()
    baseInfoList[playerUid] = entity
    entity.playerID = playerUid
  end
  return entity
end

function this:getPlayerUid(baseInfo)
  return baseInfo.id
end

function this:getPlayerZoneId(baseInfo)
  return baseInfo.zone_id
end

function this:getPlayerName(baseInfo)
  return baseInfo.name
end

function this:getPlayerSex(baseInfo)
  return baseInfo.sex
end

function this:getPlayerLevel(baseInfo)
  local playerLevelTpl = L_GameTpl:getPlayerLevelTpl()
  local minLv = playerLevelTpl:getId(playerLevelTpl.data[1])
  local maxLv = playerLevelTpl:getId(playerLevelTpl.data[#playerLevelTpl.data])
  local curLv = math.clamp(baseInfo.lv, minLv, maxLv)
  return curLv, curLv == maxLv
end

function this:getPlayerOffLineTime(baseInfo)
  return baseInfo.offlinetm
end

function this:getPlayerOnLineTime(baseInfo)
  return baseInfo.onlinetm
end

function this:getPlayerIsOnline(baseInfo)
  return baseInfo.onlinetm - baseInfo.offlinetm >= 0
end

function this:getPlayerIsBusy(baseInfo)
  return baseInfo.is_busy
end

function this:getPlayerAvatars(baseInfo, avatarTextureIndex)
  for i, v in pairs(baseInfo.wardrobe.avatars or {}) do
    if v.avatar_type == L_Const.avatarTextureIndex2screenShotType[avatarTextureIndex] then
      return v.avatar_url
    end
  end
end

function this:getPlayerAvatarsHead(baseInfo)
  return string.isEmpty(baseInfo.little_avatar) and self:getPlayerAvatars(baseInfo, L_Const.avatarTextureIndex.head) or baseInfo.little_avatar
end

function this:getPlayerAvatarsFormationHead(baseInfo)
  return self:getPlayerAvatars(baseInfo, L_Const.avatarTextureIndex.half_formation)
end

function this:getPlayerWardrobe(baseInfo)
  return baseInfo.wardrobe
end

function this:getPlayerSign(baseInfo)
  return baseInfo.sign
end

function this:getPlayerAccount(baseInfo)
  return baseInfo.account
end

function this:getPlayerRegisterTime(baseInfo)
  return baseInfo.regtm
end

function this:getPlayerDiamond(baseInfo)
  return baseInfo.diamond
end

function this:getPlayerExp(baseInfo)
  return baseInfo.exp
end

function this:getPlayerAchievement(baseInfo)
  local res = {
    0,
    0,
    0
  }
  if baseInfo == nil or baseInfo.info.achievement == nil then
    return res
  end
  for i, v in pairs(baseInfo.info.achievement) do
    res[i] = v
  end
  return res
end

function this:getPlayerDisplayHero(baseInfo)
  local data = baseInfo.info or {}
  local hero = data.hero or {}
  local res = {}
  for i, v in pairs(hero) do
    res[v.pos] = v
  end
  return res
end

function this:getPlayerDisplayPet(baseInfo)
  if baseInfo == nil or baseInfo.info.pet == nil then
    return {}
  end
  return baseInfo.info.pet
end

function this:getPreTitle(baseInfo)
  return baseInfo.preffix_title == 0 and 171000 or baseInfo.preffix_title
end

function this:getLaterTitle(baseInfo)
  return baseInfo.suffix_title == 0 and 172000 or baseInfo.suffix_title
end

function this:getPlayerBirthday(baseInfo)
  return baseInfo.birthday
end

function this:getIsFriend(guid)
  local player = self:getPlayerItem(self.data.friendList, guid)
  return not table.isEmpty(player)
end

function this:getIsFriendApplication(guid)
  local player = self:getPlayerItem(self.data.friendApplicationList, guid)
  return not table.isEmpty(player)
end

function this:getIsRecentTeam(guid)
  local player = self:getPlayerItem(self.data.recentTeamList, guid)
  return not table.isEmpty(player)
end

function this:getIsBlackList(guid)
  local player = self:getPlayerItem(self.data.blackList, guid)
  return not table.isEmpty(player)
end

return this
