local this = class("homeBuildingCollectionTpl")

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

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

function this:getType(tpl)
  return tpl.type
end

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

function this:getStorageMax(tpl)
  return tpl.storageMax
end

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

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

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

function this:getMiniIcon(tpl)
  return tpl.miniIcon or "Altas/HomeButton/tex_home_entrance_icon_suishichang.png"
end

function this:getFrameTexture(tpl)
  return tpl.frameTexture
end

function this:getIcon(tpl)
  return tpl.icon
end

function this:getUpgradeDesc(tpl)
  local res = {}
  for _, key in ipairs(tpl.upgradeDesc) do
    table.insert(res, L_Config:provider(key))
  end
  return res
end

function this:getUpgradeCondition(tpl)
  return tpl.upgradeCondition
end

function this:getMaterial(tpl)
  return tpl.material
end

function this:getPetCapacity(tpl)
  return tpl.petCapacity
end

function this:getPetSize(tpl)
  return tpl.petSize
end

function this:getMaxLevelProducts(collectionId)
  local buildings = self:getTplByCollectionId(collectionId)
  local tpl_maxLevel = buildings[table.count(buildings)]
  return tpl_maxLevel.products, tpl_maxLevel.extraProducts
end

function this:getTplByCollectionId(collectionId)
  local homeCollectionWorldTpl = L_GameTpl:getHomeCollectionWorldTpl()
  local tpl_collection = homeCollectionWorldTpl:getTplById(collectionId)
  local groupId = homeCollectionWorldTpl:getGroupId(tpl_collection)
  return self.groupData[groupId]
end

function this:getIsNeedPet(tpl)
  return tpl.isNeedPet
end

function this:getPetPosition(tpl)
  local pos = tpl.petPosition
  return L_Vector3.new(pos[1], pos[2], pos[3])
end

function this:getPetRotation(tpl)
  local pos = tpl.petRotation
  return L_Vector3.new(pos[1], pos[2], pos[3])
end

function this:getCameraVerticalAngle(tpl)
  return tpl.cameraVerticalAngle
end

function this:getCameraHorizontalAngle(tpl)
  return tpl.cameraHorizontalAngle
end

function this:getCameraDistance(tpl)
  return tpl.cameraDistance
end

function this:getLaborType(tpl)
  return tpl.laborType
end

return this
