local this = class("gameEventStore", G_BaseStore)
local _GameEventTpl = L_GameTpl:getGameEventsTpl()
this.baseGameEventCls = require(L_R.store .. "gameEvent.baseGameEvent")
this.gameEventDataCls = require(L_R.store .. "gameEvent.gameEventData")
this.event = {
  gameEventSync = "gameEventSync"
}
this:importPartialClass(require(L_R.store .. "gameEvent.gameEventState"))
this:importPartialClass(require(L_R.store .. "gameEvent.gameEventConfig"))

function this:syncGameEventDatas(protoData, errorCode)
  if errorCode ~= L_Const.errorCode.ErrCodeSucc or not protoData then
    return
  end
  for _, data in ipairs(protoData.confs or L_Const.emptyTable) do
    local id = data.activity_id
    if not L_SystemUnlockStore:getSystemIsOpen(L_SystemConst.enum.gameAct) then
      L_ReddotManager:markNew(L_ReddotManager.DotDef.GameAct_New, id)
    end
    if self._init == true and not self.data.gameEventDatas[id] then
      L_ReddotManager:markNew(L_ReddotManager.DotDef.GameAct_New, id)
    end
    self.data.gameEventDatas[id] = self.data.gameEventDatas[id] or this.gameEventDataCls.new(id)
    self.data.gameEventDatas[id]:populate(data)
  end
  for _, data in ipairs(protoData.activitys or L_Const.emptyTable) do
    local id = data.id
    if not self.data.gameEventDatas[id] then
      printf("\230\180\187\229\138\168" .. id .. "\230\178\161\230\156\137\230\151\182\233\151\180\230\149\176\230\141\174(\229\137\141\231\171\175\232\174\176\229\189\149LOG)")
    else
      self.data.gameEventDatas[id]:populateEventData(data)
    end
  end
  for _, id in ipairs(protoData.del_activitys or L_Const.emptyTable) do
    if self.data.gameEventDatas[id] then
      self.data.gameEventDatas[id]:dispose()
      self.data.gameEventDatas[id] = nil
    end
  end
  self:call(this.event.gameEventSync)
  self._init = true
end

function this:req_gameEventDatas(callback)
  L_Net:sendMessage(MsgGenCode.CSProtoActivityGet, nil, function(rspData, errorCode)
    self:syncGameEventDatas(rspData, errorCode)
    if callback and errorCode == L_Const.errorCode.ErrCodeSucc then
      callback()
    end
  end)
end

function this:markAllGameEventReddot()
  for _, gameEvent in pairs(self.data.gameEventDatas) do
    local tpl = _GameEventTpl:getTplById(gameEvent.id)
    local canShow = _GameEventTpl:getUnlockShow(tpl)
    if canShow == 1 then
      L_ReddotManager:markNew(L_ReddotManager.DotDef.GameAct_New, gameEvent.id)
    end
  end
end

return this
