local this = class("worldExploreStore", G_BaseStore)
local _exploreTpl = L_GameTpl:getExploreTpl()
this.event = {
  MapExploreReward = "MapExploreReward",
  ExplorationSync = "ExplorationSync",
  mapExploreMissionComplete = "mapExploreMissionComplete",
  mapExploreLvUp = "mapExploreLvUp"
}
this:importPartialClass(require(L_R.store .. "worldExplore.worldExploreState"))
this:importPartialClass(require(L_R.store .. "worldExplore.worldExploreAction"))

function this:checkMissionStatusChange(missionInfoList)
  if not self.data.setHasInitSync or table.isEmpty(missionInfoList) then
    return
  end
  for i, missionInfo in pairs(missionInfoList) do
    if not self.data.missionCompleteMap[missionInfo.exploration_id] and missionInfo.complete == true then
      self.data.missionCompleteMap[missionInfo.exploration_id] = true
      L_FlyMsgManager:showMapExploreComplete(missionInfo)
      self:call(self.event.mapExploreMissionComplete, missionInfo)
    end
  end
end

function this:checkExploreLvChange(exploreInfoList)
  if not self.data.setHasInitSync or table.isEmpty(exploreInfoList) then
    return
  end
  for i, exploreInfo in pairs(exploreInfoList) do
    if exploreInfo.lv ~= self.data.curSceneLevel[exploreInfo.map_id].lv then
      self.data.curSceneLevel[exploreInfo.map_id].lv = exploreInfo.lv
      L_FlyMsgManager:showMapExploreLvUp(exploreInfo)
      self:call(self.event.mapExploreLvUp, exploreInfo)
    end
  end
end

function this:initExploreServerData()
  for i, v in pairs(self.data.missionInfo) do
    if v and v.complete == true then
      self.data.missionCompleteMap[v.exploration_id] = true
    end
  end
  if table.isEmpty(self.data.exploreInfo) then
    local data = _exploreTpl:getMapIdGroupExploreTpl()
    for i, v in pairs(data) do
      self.data.curSceneLevel[i] = {map_id = i, lv = 1}
    end
  else
    for i, v in pairs(self.data.exploreInfo) do
      self.data.curSceneLevel[v.map_id] = {
        map_id = v.map_id,
        lv = v.lv
      }
    end
  end
end

return this
