local this = class("homeProsperityTpl")

function this:init(config)
  self.data = config
  self.sortList = {}
  for i, v in pairs(self.data) do
    table.insert(self.sortList, v)
  end
  table.sort(self.sortList, function(a, b)
    return a.prosperity < b.prosperity
  end)
end

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

function this:getReward(tpl)
  return tpl.reward
end

function this:getProsperity(tpl)
  return tpl.prosperity
end

function this:getIcon(tpl)
  local tmp = {}
  for _, v in ipairs(tpl.icon) do
    table.insert(tmp, L_Config:getPathByHash(v))
  end
  return tmp
end

function this:getUnlockDesc(tpl)
  return L_Config:provider(tpl.unlockDesc)
end

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

function this:getNextTplByProsperity(curProsperity)
  for i, v in pairs(self.sortList) do
    if curProsperity < v.prosperity then
      return v
    end
  end
end

function this:getTplByProsperity(curProsperity)
  for i, v in pairs(self.sortList) do
    if curProsperity >= v.prosperity then
      return v
    end
  end
end

function this:getAllTpl()
  return self.data
end

return this
