local this = {}

function this:req_CSProtoRogueLikeUnlockResearch(id, callback)
  local data = {u32 = id}
  L_Net:sendMessage(MsgGenCode.CSProtoRogueLikeUnlockResearch, data, function(rspData, errorCode)
    if errorCode == L_Const.errorCode.ErrCodeSucc and callback then
      callback()
    end
  end)
end

function this:req_CSProtoRogueLikeGetSurveyReward(ids, callback)
  local data = {u32s = ids}
  L_Net:sendMessage(MsgGenCode.CSProtoRogueLikeGetSurveyReward, data, function(rspData, errorCode)
    local rewards = rspData.rewards
    if errorCode == L_Const.errorCode.ErrCodeSucc then
      if not table.isEmpty(rewards) then
        L_RewardManager:showPage(rewards, rspData.src)
      end
      if callback then
        callback()
      end
    end
  end)
end

function this:req_CSProtoRogueLikeGetMonthReward(eventGuid, callback)
  local data = {
    version = 1,
    id = {}
  }
  L_Net:sendMessage(MsgGenCode.CSProtoRogueLikeGetMonthReward, data, function(rspData, errorCode)
    if errorCode == L_Const.errorCode.ErrCodeSucc and callback then
      callback()
    end
  end)
end

function this:rsp_syncRogueExternalData(sData)
  local data = sData
  if data.rnum then
    self.data.external.rnum = self.data.external.rnum or {}
    for _, v in pairs(data.rnum) do
      local num = v
      self.data.external.rnum[num.version] = num.num
    end
  end
  if data.mnum then
    self.data.external.mnum = self.data.external.mnum or {}
    for _, v in pairs(data.mnum) do
      local num = v
      self.data.external.mnum[num.version] = num.num
    end
  end
  if data.survey_num then
    self.data.external.survey_num = data.survey_num
  end
  if data.refresh_tm then
    self.data.external.refresh_tm = data.refresh_tm
  end
  if data.surveys then
    self.data.external.surveys = self.data.external.surveys or {}
    for _, v in pairs(data.surveys) do
      self.data.external.surveys[v] = v
    end
  end
  if data.del_surveys then
    for _, v in pairs(data.del_surveys) do
      self.data.external.surveys[v] = nil
    end
  end
  if data.unlocks then
    self.data.external.unlocks = self.data.external.unlocks or {}
    for _, v in pairs(data.unlocks) do
      local archive = v
      self.data.external.unlocks[archive.id] = archive
    end
  end
  if data.difficulty then
    self.data.external.difficulty = data.difficulty
  end
  if data.version then
    self.data.external.version = data.version
  end
  if data.max_difficulty then
    self.data.external.max_difficulty = data.max_difficulty
  end
  if data.researchs then
    self.data.external.researchs = self.data.external.researchs or {}
    for _, v in pairs(data.researchs) do
      self.data.external.researchs[v] = v
    end
  end
  if data.months then
    self.data.external.months = self.data.external.months or {}
    for _, v in pairs(data.months) do
      self.data.external.months[v] = v
    end
  end
  self:call(self.event.refreshExternalData)
end

return this
