local ParkourManager = BaseClass("ParkourManager")
local Localization = CS.GameEntry.Localization
local __init = function(self)
  self.lastPassTime = 0
  self.curStageId = 0
  self.passStageId = 0
end
local __delete = function(self)
end
local InitData = function(self, message)
  if message.stageFeatureInfo ~= nil then
    local u = message.stageFeatureInfo
    local id = tonumber(u.stageId)
    local time = tonumber(u.featureRewardTimeStamp)
    self:ProcessData(id, time)
  else
    self:ProcessData(0, 0)
  end
end
local UpdateData = function(self, stageId, time, reward)
  self:ProcessData(stageId, time)
  self.reward = reward
  self.rewardStageId = stageId
end
local ProcessData = function(self, stageId, time)
  self.lastPassTime = time
  self.curStageId = math.max(stageId, self.curStageId)
  self.passStageId = math.max(stageId, self.passStageId)
  local meta = {}
  LocalController:instance():visitTable(LuaEntry.Player:GetABTestTableName(TableName.LW_Stage_Feature), function(id, lineData)
    table.insert(meta, {
      id = lineData:getValue("id"),
      order = lineData:getValue("order")
    })
  end)
  table.sort(meta, function(a, b)
    return a.order < b.order
  end)
  local curOrder = 0
  if 0 < stageId then
    local meta = LocalController:instance():getLine(LuaEntry.Player:GetABTestTableName(TableName.LW_Stage_Feature), stageId)
    if meta then
      curOrder = meta.order
    end
  end
  for _, lineData in ipairs(meta) do
    if curOrder < lineData.order then
      self.curStageId = math.max(self.curStageId, lineData.id)
      break
    end
  end
  EventManager:GetInstance():Broadcast(EventId.UpdateParkourStage)
end
local AlreadyPass = function(self, id)
  return id < self.curStageId
end
ParkourManager.__init = __init
ParkourManager.__delete = __delete
ParkourManager.InitData = InitData
ParkourManager.UpdateData = UpdateData
ParkourManager.ProcessData = ProcessData
ParkourManager.AlreadyPass = AlreadyPass
return ParkourManager
