local this = {}
local tInsert = table.insert
local skillTpl = L_GameTpl:getSkillTpl()

function this:collectBattleHeroSkills(battleType, battleHeros)
  for _, v in pairs(battleHeros) do
    printf("battle hero:", v)
    local heroGuid = v.hero_guid
    v.heroSkills = {}
    v.spirSkills = {}
    v.accessorySkills = {}
    local heroInfo
    heroInfo = L_HeroStore:getHero(heroGuid)
    self:creatFightHeroInfo(v.hero_conf_id, heroInfo, v)
  end
end

function this:creatFightHeroInfo(heroId, heroInfo, fightHeroInfo)
  local skills = L_HeroManager:getHeroAllSystemSkills(heroInfo)
  for _, skill in pairs(skills) do
    if self:canSkillInput2Battle(skill.skillId) then
      tInsert(fightHeroInfo.heroSkills, {
        skillId = skill.skillId,
        level = skill.skillLevel
      })
    end
  end
  if fightHeroInfo.oinfo then
    local accessoryList = {}
    for __, o in ipairs(fightHeroInfo.oinfo) do
      if o then
        tInsert(accessoryList, o.id)
      end
    end
    if fightHeroInfo.suitSkills and fightHeroInfo.suitSkills.skills and fightHeroInfo.suitSkills.skills.skills then
      for __, skill in pairs(fightHeroInfo.suitSkills.skills.skills) do
        if self:canSkillInput2Battle(skill.skill_id) then
          tInsert(fightHeroInfo.accessorySkills, skill.skill_id)
        end
      end
    end
  end
  local heroStar = L_HeroStore:getHeroStar(heroInfo)
  if 0 < heroStar then
    local starSkills = L_HeroManager:getHeroStarSkills(heroId, heroStar)
    for __, starSkill in ipairs(starSkills) do
      if self:canSkillInput2Battle(starSkill) then
        tInsert(fightHeroInfo.heroSkills, {skillId = starSkill, level = 1})
      end
    end
  end
  if fightHeroInfo.winfo then
    local wId = fightHeroInfo.winfo.wid
    local wLevel = fightHeroInfo.winfo.level
    local wRank = fightHeroInfo.winfo.rank
    local wAdvance = fightHeroInfo.winfo.advance
    local wSkills = L_SpiritronManager:getSpiritronSkills(wId, wLevel, wRank)
    for __, wSkill in ipairs(wSkills) do
      if self:canSkillInput2Battle(wSkills) then
        fightHeroInfo.spirSkills[wSkill] = wAdvance
      end
    end
  end
end

function this:canSkillInput2Battle(skillId)
  local tpl = skillTpl:getTplById(skillId)
  return tpl and skillTpl:getSkillType(tpl) ~= L_Const.skillFuncType.number
end

return this
