local this = class("catalogStore", G_BaseStore)
this.event = {
  refreshCatalog = "catalogStore_refreshCatalog",
  updateCatalog = "catalogStore_updateCatalog"
}
this:importPartialClass(require(L_R.store .. "catalog.catalogAction"))
this:importPartialClass(require(L_R.store .. "catalog.catalogState"))

function this:setHasInitSync(bool)
  self.data.setHasInitSync = bool
end

function this:setCatalogHasInitSync(bool)
  self.data.setCatalogHasInitSync = bool
end

function this:calcPetAttr(petId)
  if self.data.petAttr[petId] then
    table.clear(self.data.petAttr[petId])
  end
  local petTpl = L_GameTpl:getPetTpl():getTplById(petId)
  local elementId = L_GameTpl:getPetTpl():getFirstElement(petTpl)
  if self.data.petElementAttr[elementId] then
    for attrId, _ in pairs(self.data.petElementAttr[elementId]) do
      if self.data.petElementAttr[elementId][attrId][petId] then
        self.data.petElementAttr[elementId][attrId][petId] = 0
      end
    end
  end
  local taskLevel = self.data.petCatalog[petId].lv
  local petAttr, eleAttr
  for lv = 1, taskLevel do
    local levelTpl = L_GameTpl:getIconographyLevelTpl():getTplByLvPetId(lv, petId)
    local rewardType = L_GameTpl:getIconographyLevelTpl():getType(levelTpl)
    for _, rId in pairs(rewardType) do
      local rewardTpl = L_GameTpl:getIconographyTypeTpl():getTplById(rId)
      for _, attr in pairs(rewardTpl.abilities) do
        local attrId = attr[1]
        local attrVal = attr[2]
        if rewardTpl.rewardtype and rewardTpl.rewardtype == 5009 then
          if not self.data.petAttr[petId] then
            self.data.petAttr[petId] = {}
          end
          if not self.data.petAttr[petId][attrId] then
            self.data.petAttr[petId][attrId] = 0
          end
          self.data.petAttr[petId][attrId] = self.data.petAttr[petId][attrId] + attrVal
        end
        if rewardTpl.rewardtype and rewardTpl.rewardtype == 5010 then
          if not self.data.petElementAttr[elementId] then
            self.data.petElementAttr[elementId] = {}
          end
          if not self.data.petElementAttr[elementId][attrId] then
            self.data.petElementAttr[elementId][attrId] = {}
          end
          if not self.data.petElementAttr[elementId][attrId][petId] then
            self.data.petElementAttr[elementId][attrId][petId] = 0
          end
          self.data.petElementAttr[elementId][attrId][petId] = self.data.petElementAttr[elementId][attrId][petId] + attrVal
        end
      end
    end
  end
end

function this:setNotNew(petId)
  L_CommonUtil.setLocalValue("petCatalogNew" .. tostring(petId), false)
end

function this:setNotTask(petId)
  L_CommonUtil.setLocalValue("petCatalogTask" .. tostring(petId), false)
end

return this
