local this = class("skillLevelTpl")

function this:init(config)
  self.data = config
  self.dataDic = {}
  for i, v in pairs(config) do
    if not self.dataDic[v.skillId] then
      self.dataDic[v.skillId] = {}
    end
    self.dataDic[v.skillId][v.level] = v
  end
end

function this:getTplByIdAndLevel(skillId, level)
  if not self.dataDic[skillId] then
    errorf("SkillLevel\232\161\168\230\156\137\233\148\153\232\175\175\230\138\128\232\131\189\230\149\176\230\141\174" .. skillId)
  end
  level = level or 1
  return self.dataDic[skillId][level]
end

function this:getMaxLevelById(skillId)
  local maxLevel = 1
  if self.dataDic[skillId] == nil then
    return maxLevel
  end
  for i, v in pairs(self.dataDic[skillId]) do
    local prevLevelCfg = self.dataDic[skillId][i - 1]
    if i > maxLevel and self:getCanUp(prevLevelCfg) then
      maxLevel = i
    end
  end
  return maxLevel
end

function this:getSubSkillId(tpl)
  return tpl.subSkillId
end

function this:getItem(tpl)
  return tpl.item
end

function this:getCanUp(tpl)
  return tpl.canUp ~= 0
end

function this:getValue(tpl)
  local value = tpl.value
  local res = {}
  for i, v in pairs(value) do
    table.insert(res, L_Config:provider(v))
  end
  return res
end

function this:getName(tpl)
  local value = tpl.name
  local res = {}
  for i, v in pairs(value) do
    table.insert(res, L_Config:provider(v))
  end
  return res
end

function this:getSkillDescribe(tpl)
  return L_Config:provider(tpl.skillDescribe)
end

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

function this:getGold(tpl)
  return tpl.gold
end

function this:getHeroLevel(tpl)
  return tpl.heroLevel or 0
end

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

function this:getSkillGroupId(tpl)
  return tpl.skillId
end

function this:getSubSkillId(tpl)
  return tpl.subSkillId
end

function this:getSkillSpecialDesc(tpl)
  return L_Config:provider(tpl.skillSpecialDesc)
end

return this
