local this = class("petAttrInfo")

function this:ctor(petGuid)
  self.petGuid = petGuid
  self.modules = {}
  self.attrMap = {}
  self.inherentSkills = {}
  self.geneSkills = {}
end

function this:addModule(sModule)
  local m = self:getModule(sModule.module_type, true)
  if sModule.sub_modules then
    for _, v in ipairs(sModule.sub_modules) do
      m:addSub(sModule.module_type, v)
    end
  end
end

function this:getModule(moduleType, isCreate)
  local m = self.modules[moduleType]
  if m == nil and isCreate then
    m = require(L_R.store .. "pet.data.petAttrModuleInfo").new(moduleType)
    self.modules[moduleType] = m
  end
  return m
end

function this:updateAttrMap()
  self.attrMap = {}
  for _, module in pairs(self.modules) do
    for _, sub in pairs(module.subModules) do
      self:packAttr(sub.attrs, self.attrMap)
    end
  end
  return self.attrMap
end

function this:packAttr(attr, attrMap)
  for id, v in pairs(attr) do
    if attrMap[id] then
      attrMap[id] = attrMap[id] + v
    else
      attrMap[id] = v
    end
  end
end

function this:updateSkillMap()
  self.inherentSkills = {}
  self.geneSkills = {}
  for _, module in pairs(self.modules) do
    for _, sub in pairs(module.subModules) do
      self:packSkillMap(sub.inherent_skills, self.inherentSkills)
      self:packSkillMap(sub.gene_skills, self.geneSkills)
    end
  end
end

function this:packSkillMap(srcSkillMap, dstSkillMap)
  for skillId, v in pairs(srcSkillMap) do
    table.insert(dstSkillMap, v)
  end
end

return this
