local this = class("spiritronRankTpl")

function this:init(config)
  self.data = {}
  for i, v in pairs(config) do
    if self.data[v.spiritronId] == nil then
      self.data[v.spiritronId] = {}
    end
    self.data[v.spiritronId][v.rank] = v
  end
end

function this:getTplList()
  return self.data
end

function this:getSpiritronId(tpl)
  return tpl.spiritronId
end

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

function this:getRank(tpl)
  return tpl.rank
end

function this:getRankUpCoin(tpl)
  return tpl.rankUpCoin
end

function this:getRankLevelLimit(tpl)
  return tpl.rankLevelLimit
end

function this:getRankUpItem(tpl)
  return tpl.rankUpItem
end

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

function this:getChildren(spiritronId)
  return self.data[spiritronId]
end

function this:getTplByIdAndRank(spiritronId, rank)
  return self.data[spiritronId][rank]
end

function this:getRankUpAttributeAll(tpl)
  return tpl.rankUpAttributeAll
end

function this:getRankUpAttribute(tpl)
  return tpl.rankUpAttribute
end

function this:getCondition(tpl)
  return tpl.condition
end

function this:getMaxRank(spiritronId)
  local childs = self:getChildren(spiritronId)
  local rank = 1
  for _, child in pairs(childs) do
    if rank < child.rank then
      rank = child.rank
    end
  end
  return rank
end

return this
