local this = class("homeBuildingCanteenTpl")

function this:init(config)
  self.data = config
end

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

function this:getProducts(tpl)
  return tpl.products
end

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

function this:getNote(tpl)
  return tpl.note_
end

function this:getUnlockMap(groupId)
  local homeBuildingTpl = L_GameTpl:getHomeBuildingTpl()
  local buildings = homeBuildingTpl:getGroupData(groupId)
  local maxLevelBuildingId = homeBuildingTpl:getId(buildings[table.count(buildings)])
  local allProducts = self.data[maxLevelBuildingId].products
  local res = {}
  for i, v in pairs(allProducts) do
    for i1, v1 in ipairs(buildings) do
      local tpl_building_pro = self:getTplById(homeBuildingTpl:getId(v1))
      local node, index = table.ipairsFind(tpl_building_pro.products, function(value)
        return value == v
      end)
      if index then
        res[v] = homeBuildingTpl:getLevel(v1)
        break
      end
    end
  end
  return res
end

return this
