local this = {}

function this:req_CSProtoCollectBuildCreate(guid, sourceBuild, callback)
  local data = {
    collect_id = guid,
    source_build = sourceBuild or 0
  }
  L_Net:sendMessage(MsgGenCode.CSProtoCollectBuildCreate, data, function(rspData, errorCode)
    if callback then
      callback(errorCode)
    end
  end)
end

function this:req_CSProtoCollectStart(guid, planTime, callback)
  local data = {guid = guid, plan_time = planTime}
  L_Net:sendMessage(MsgGenCode.CSProtoCollectStart, data, function(rspData, errorCode)
    if callback then
      callback(errorCode)
    end
  end)
end

function this:req_CSProtoCollectStop(guid, callback)
  local data = {u32 = guid}
  L_Net:sendMessage(MsgGenCode.CSProtoCollectStop, data, function(rspData, errorCode)
    if callback then
      callback(errorCode)
    end
  end)
end

function this:req_CSProtoCollectGetReward(guidList, sourceBuild, callback)
  local data = {
    guid = guidList,
    source_build = sourceBuild or 0
  }
  L_Net:sendMessage(MsgGenCode.CSProtoCollectGetReward, data, function(rspData, errorCode)
    if callback then
      callback(rspData, errorCode)
    end
  end)
end

function this:req_CSProtoCollectGetAllReward(callback)
  L_Net:sendMessage(MsgGenCode.CSProtoCollectGetAllReward, nil, function(rspData, errorCode)
    if callback then
      callback(rspData, errorCode)
    end
  end)
end

function this:req_CSProtoGetCollectRewardInfo(collectionId, callback)
  local data = {u32 = collectionId}
  L_Net:sendMessage(MsgGenCode.CSProtoGetCollectRewardInfo, data, function(rspData, errorCode)
    if errorCode == L_Const.errorCode.ErrCodeSucc then
      self.data.collectionMap[rspData.collect_build_datas.guid] = rspData.collect_build_datas
      if callback then
        callback()
      end
    end
  end)
end

function this:rsp_syncCollect(data)
  local updateList = {}
  for i, v in ipairs(data) do
    local collection = v
    if self.data.collectionMap[collection.guid] ~= nil then
      updateList[collection.guid] = collection.guid
    end
    self.data.collectionMap[collection.guid] = collection
  end
  self:call(self.event.refreshCollection)
  if not table.isEmpty(updateList) then
    self:call(self.event.updateCollection, updateList)
  end
  self:call(self.event.refreshModuleHomeCenterBuildingManageReceiveAllDot)
end

return this
