local this = class("dungeonEntrustTpl")

function this:init(config)
  self.data = config
  self.modeInfo = {}
  local groupIdToIndex = {}
  for _, v in pairs(config) do
    if not self.modeInfo[v.difficulty] then
      self.modeInfo[v.difficulty] = {}
    end
    if not groupIdToIndex[v.difficulty] then
      groupIdToIndex[v.difficulty] = {}
    end
    if not groupIdToIndex[v.difficulty][v.groupId] then
      groupIdToIndex[v.difficulty][v.groupId] = #self.modeInfo[v.difficulty] + 1
      table.insert(self.modeInfo[v.difficulty], {
        groupId = v.groupId,
        levelInfos = {}
      })
    end
    table.insert(self.modeInfo[v.difficulty][groupIdToIndex[v.difficulty][v.groupId]].levelInfos, v)
  end
  for _, v1 in pairs(self.modeInfo) do
    for _, v2 in ipairs(v1) do
      table.sort(v2, function(a, b)
        if a.sortId == b.sortId then
          return a.id < b.id
        end
        return a.sortId < b.sortId
      end)
    end
  end
end

function this:getTplById(id)
  return self.data[id]
end

function this:getId(tpl)
  return tpl.id
end

function this:getName(tpl)
  return L_Config:provider(tpl.name)
end

function this:getDifficulty(tpl)
  return tpl.difficulty
end

function this:getEntrustNpcName(tpl)
  return L_Config:provider(tpl.entrustNpc)
end

function this:getIntroduce(tpl)
  return L_Config:provider(tpl.introduce)
end

function this:getDungeonId(tpl)
  return tpl.dungeonId
end

function this:getRewardShow(tpl)
  return L_DataUtil.parseRangeRewardConfig(tpl.rewardShow)
end

function this:getOneStarRewardShow(tpl)
  return L_DataUtil.parseRewardConfig(tpl.starRewardShow1)
end

function this:getTwoStarRewardShow(tpl)
  return L_DataUtil.parseRewardConfig(tpl.starRewardShow2)
end

function this:getThreeStarRewardShow(tpl)
  return L_DataUtil.parseRewardConfig(tpl.starRewardShow3)
end

function this:getTaskShow(tpl)
  return tpl.taskShow
end

function this:getTaskUnlock(tpl)
  return tpl.taskUnlock
end

function this:getTag(tpl)
  return tpl.Tag
end

function this:getRecommendLevel(tpl)
  return tpl.level
end

function this:getDungeonTarget(tpl)
  return L_Config:provider(tpl.dungeonTarget)
end

function this:getDifficultyNum()
  return table.count(self.modeInfo)
end

function this:getInfoByDifficulty(difficulty)
  return self.modeInfo[difficulty]
end

function this:getModeInfo()
  return self.modeInfo
end

function this:getEnergyConsume(tpl)
  return tpl.stamina
end

return this
