local this = {}

function this:req_createDungeon(groupId, difficulty, callBack)
  local data = {group_id = groupId, difficulty = difficulty}
  L_Net:sendMessage(MsgGenCode.CSProtoCampaignCreate, data, function(rspData, errorCode)
    if errorCode == L_Const.errorCode.ErrCodeSucc and callBack then
      callBack(rspData)
    end
  end)
end

function this:req_exitDungeon(callBack)
  self.isReqExitDungeon = true
  L_Net:sendMessage(MsgGenCode.CSProtoCampaignQuit, nil, function(data, errorCode)
    self.isReqExitDungeon = false
    if callBack then
      callBack()
    end
    self:resetCurDungeon()
  end)
  L_PlayerManager:shotdownSendOperator()
end

function this:isExitingDungeon()
  return self.isReqExitDungeon
end

function this:req_enterDungeonScene(scene_id, point_id, creator_id, callback)
  local data = {
    scene_id = scene_id,
    point_id = point_id,
    creator_id = creator_id
  }
  L_Net:sendMessage(MsgGenCode.CSProtoEnterDungeonScene, data, function(data, errorCode)
    if callback then
      callback()
    end
  end)
  L_PlayerManager:shotdownSendOperator()
end

function this:req_settleDungeon(callBack)
  L_Net:sendMessage(MsgGenCode.CSProtoCampaignEnd, nil, function(rspData, errorCode)
    self:syncDungeonSettle(rspData)
    if callBack then
      callBack()
    end
    self:resetCurDungeon()
  end)
end

function this:syncDungeonSettle(data)
  self.data.dungeonCampaignEnd = data
end

function this:rsp_instanceDungeonList(data)
  self.data.dungeonInstanceInfo.infos = self.data.dungeonInstanceInfo.infos or {}
  self.data.dungeonInstanceInfo.entrys = self.data.dungeonInstanceInfo.entrys or {}
  for i, v in pairs(data.infos or {}) do
    local info = v
    self.data.dungeonInstanceInfo.infos[info.ins_id] = info
  end
  for i, v in pairs(data.entrys or {}) do
    local entry = v
    self.data.dungeonInstanceInfo.entrys[entry.group_id] = entry
  end
end

return this
