local this = {}

function this:req_enterEntrustLevel(levelId, callback)
  local data = {entrust_id = levelId}
  L_Net:sendMessage(MsgGenCode.CSProtoEnterEntrust, data, function(rspData, errorCode)
    if 0 < errorCode then
      return
    end
    if callback then
      callback()
    end
  end)
end

function this:req_getEntrustReward(rewardIdList, callback)
  local data = {reward_id_list = rewardIdList}
  L_Net:sendMessage(MsgGenCode.CSProtoEntrustStarReward, data, function(rspData, errorCode)
    if 0 < errorCode then
      return
    end
    L_RewardManager:showPage(rspData.rewards, rspData.src)
    if callback then
      callback()
    end
  end)
end

function this:req_CSProtoTeachStart(taskId, callback)
  local data = {u32 = taskId}
  L_Net:sendMessage(MsgGenCode.CSProtoTeachStart, data, function(rspData, errorCode)
    if 0 < errorCode then
      return
    end
    if callback then
      callback()
    end
  end)
end

function this:rsp_entrustInfo(data, errorCode)
  if not data or not data.data then
    return
  end
  for _, v in ipairs(data.data) do
    self.data.entrustInfo[v.entrust_id] = {}
    self.data.entrustInfo[v.entrust_id].entrust_star = v.entrust_star
    self.data.entrustInfo[v.entrust_id].success_time = v.success_time
  end
  self:call(self.event.entrustInfoRefresh)
end

function this:rsp_entrustReward(data, errorCode)
  if not data or not data.data then
    return
  end
  for _, v in ipairs(data.data) do
    self.data.entrustReward[v.reward_id] = {}
    self.data.entrustReward[v.reward_id].reward_id = v.reward_id
    self.data.entrustReward[v.reward_id].reward_time = v.reward_time
  end
  self:call(self.event.entrustRewardRefresh)
end

function this:rsp_entrustKiboInfo(data, errorCode)
  if not data or not data.data then
    return
  end
  for _, v in ipairs(data.data) do
    self.data.entrustKiboInfo[v.kibo_dule_id] = {}
    self.data.entrustKiboInfo[v.kibo_dule_id].kibo_dule_id = v.kibo_dule_id
    self.data.entrustKiboInfo[v.kibo_dule_id].entrust_star = v.entrust_star
    self.data.entrustKiboInfo[v.kibo_dule_id].success_time = v.success_time
  end
end

function this:rsp_syncTrainTaskCompletedData(data, errorCode)
  data = data or {}
  for i, v in pairs(data) do
    for _, v2 in ipairs(v) do
      self.data.trainTaskRecord[v2] = true
    end
  end
end

return this
