local this = {}
local noviceTaskTpl = L_GameTpl:getNoviceTaskTpl()
local TaskStatus = {
  NOT_COMPLET = 0,
  COMPLETE = 1,
  REWARD_RECEIVED = 2
}

function this:init()
  this.super.init(self)
  self.data = {
    taskInfosDic = {},
    taskTplDataDic = noviceTaskTpl:getTaskTplDataDic(),
    taskGroupId2GroupFinishedDic = {},
    taskGroupId2GroupProgressDic = {},
    taskGroupId2GroupMaxProgressDic = {},
    maxTaskGroupId = 0
  }
end

function this:state()
  return {}
end

function this:getTaskInfosDic()
  return self.data.taskInfosDic
end

function this:getTaskTplDataDic()
  return self.data.taskTplDataDic
end

function this:getMaxTaskGroupId()
  return self.data.maxTaskGroupId
end

function this:getTaskGroupIfFinishedById(groupId)
  return self.data.taskGroupId2GroupFinishedDic[groupId]
end

function this:getTaskGroupProgressById(groupId)
  return self.data.taskGroupId2GroupProgressDic[groupId]
end

function this:getTaskGroupMaxProgressById(groupId)
  return self.data.taskGroupId2GroupMaxProgressDic[groupId]
end

function this:getCanReceiveRewardNumber()
  local canReceiveRewardNumber = 0
  local maxUnlockeTaskGroupId = self:getMaxUnlockedTaskGroupId()
  for groupId, taskInfoList in pairs(self.data.taskInfosDic) do
    if groupId <= maxUnlockeTaskGroupId then
      if self:getTaskGroupProgressById(groupId) == self:getTaskGroupMaxProgressById(groupId) and self:getTaskGroupIfFinishedById(groupId) ~= true then
        canReceiveRewardNumber = canReceiveRewardNumber + 1
      end
      for _, taskInfo in pairs(taskInfoList) do
        if taskInfo.task_status == TaskStatus.COMPLETE then
          canReceiveRewardNumber = canReceiveRewardNumber + 1
        end
      end
    end
  end
  return canReceiveRewardNumber
end

function this:getMaxUnlockedTaskGroupId()
  local maxUnlockeTaskGroupId = 1
  for groupId, ifFinished in pairs(self.data.taskGroupId2GroupFinishedDic) do
    if ifFinished and groupId + 1 <= self.data.maxTaskGroupId and maxUnlockeTaskGroupId < groupId + 1 then
      maxUnlockeTaskGroupId = groupId + 1
    end
  end
  return maxUnlockeTaskGroupId
end

return this
