local this = {}

function this:init()
  self.super.init(self)
  self.data = {
    heroAttrDic = {}
  }
end

function this:getDefaultHeroGuid()
  return AzurWorld.heroMgr:GetDefaultHeroGuid()
end

function this:getAllHero()
  if not AzurWorld or not AzurWorld.heroMgr then
    return {}
  end
  local heroData = AzurWorld.heroMgr:GetHero()
  local res = {}
  for i, v in pairs(heroData) do
    if not self:getIsTrail(v) then
      res[i] = v
    end
  end
  return res
end

function this:getHero(heroGuid)
  if heroGuid == nil then
    return nil
  end
  return AzurWorld.heroMgr:GetHero(heroGuid)
end

function this:getHeroAttrInfo(heroGuid)
  local attrInfo = self.data.heroAttrDic[heroGuid]
  if attrInfo == nil then
    attrInfo = require(L_R.store .. "hero.data.heroAttrInfo").new(heroGuid)
    self.data.heroAttrDic[heroGuid] = attrInfo
  end
  return attrInfo
end

function this:getHeroPropertyMap(heroGuid)
  local info = self:getHeroAttrInfo(heroGuid)
  return info.attrMap
end

function this:getGuidByConfigId(configId)
  return self:getHeroGuid(AzurWorld.heroMgr:GetHeroByConfigId(math.floor(tonumber(configId))))
end

function this:getHasHero(heroConfigId)
  for i, v in pairs(self:getAllHero()) do
    if self:getHeroConfigId(v) == heroConfigId then
      return true
    end
  end
  return false
end

function this:getHeroByConfigId(heroConfigId)
  for i, v in pairs(self:getAllHero()) do
    if self:getHeroConfigId(v) == heroConfigId then
      return v
    end
  end
end

function this:getHeroGuid(hero)
  return hero.guid
end

function this:getHeroLevel(hero)
  return hero.lv or 0
end

function this:getHeroExp(hero)
  return hero.heroExp or 0
end

function this:getHeroRank(hero)
  return hero.heroRank or 0
end

function this:getHeroSpiritronGuid(hero)
  return hero.spiritronGuid or 0
end

function this:getHeroSysSkillLevel(hero)
  if type(hero.systemSkillLevel) == "table" then
    return hero.systemSkillLevel
  end
  local res = {}
  if not hero.systemSkillLevel then
    return res
  end
  for i = 0, hero.systemSkillLevel.Count - 1 do
    table.insert(res, hero.systemSkillLevel[i])
  end
  return res
end

function this:getHeroStar(hero)
  return hero.heroStar or 0
end

function this:getHeroAccessoryGuidList(hero)
  local res = {}
  if not hero.accessoryGuidList then
    return res
  end
  for i = 0, hero.accessoryGuidList.Count - 1 do
    table.insert(res, hero.accessoryGuidList[i])
  end
  return res
end

function this:getHeroPetGuid(hero)
  if not math.isEmpty(hero.trailPetId) then
    return hero.trailPetId
  end
  return hero.petId or 0
end

function this:getHeroFavorAbilityExp(hero)
  return hero.favorabilityExp or 0
end

function this:getHeroStoreFavorRewards(hero)
  local res = {}
  if not hero.storeFavorRewards then
    return res
  end
  for i = 0, hero.storeFavorRewards.Count - 1 do
    table.insert(res, hero.storeFavorRewards[i])
  end
  return res
end

function this:getHeroConfigId(hero)
  return hero.configId
end

function this:getHeroFavorAbilityLevel(hero)
  return hero.favorabilityLevel or 0
end

function this:getHeroRuneIds(hero)
  if type(hero.runeIds) == "table" then
    return hero.runeIds
  end
  local res = {}
  if not hero.runeIds then
    return res
  end
  for i = 0, hero.runeIds.Count - 1 do
    table.insert(res, hero.runeIds[i])
  end
  return res
end

function this:getHeroType(hero)
  return hero.type
end

function this:getHeroType(hero)
  return hero.type
end

function this:getTrailPet(hero)
  return hero.trailPetId or 0
end

function this:getIsTrail(hero)
  return hero:GetIsTrialHero()
end

function this:getAllCharDataByHero(heroConfigId)
  return AzurWorld.heroMgr:GetCharDataInfoList(heroConfigId)
end

function this:getUnlockCharData(heroGuid, dataType)
  local infos = self:getAllCharDataByHero(heroGuid)
  if infos then
    for typeId, info in pairs(infos) do
      if typeId == dataType then
        local res = {}
        if not info.recordIds then
          return res
        end
        for i2 = 0, info.recordIds.Count - 1 do
          table.insert(res, info.recordIds[i2])
        end
        return res
      end
    end
  end
  return {}
end

function this:getIsCharDataRead(heroGuid, dataType, dataId)
  local allData = self:getUnlockCharData(heroGuid, dataType)
  local _, index = table.ipairsFind(allData, function(v)
    return v == dataId
  end)
  return index ~= nil
end

function this:getIsPlayLevelAnim()
  return self.data.isPlayLevelAnim
end

function this:setIsPlayLevelAnim(isPlay)
  self.data.isPlayLevelAnim = isPlay
end

return this
