local DailyMustBuyManager = BaseClass("DailyMustBuyManager")
local Localization = CS.GameEntry.Localization
local __init = function(self)
  self.stages = nil
  EventManager:GetInstance():AddListener(EventId.OnPassWeek, self.RequestClaimedReward)
end
local __delete = function(self)
  self.stages = nil
  EventManager:GetInstance():RemoveListener(EventId.OnPassWeek, self.RequestClaimedReward)
end
local UpdateData = function(self, msg)
  if not msg then
    return
  end
  self.stages = msg.dailyMustList
  if not table.IsNullOrEmpty(self.stages) then
    for i, v in pairs(self.stages) do
      v.showReward = DataCenter.RewardManager:ReturnRewardParamForView(v.reward)
    end
  end
  EventManager:GetInstance():Broadcast(EventId.OnDailyMustBuyDataChanged)
  EventManager:GetInstance():Broadcast(EventId.RefreshWelfareRedDot)
end
local AddNewClaimedReward = function(self, index)
  if not index then
    return
  end
  if not table.IsNullOrEmpty(self.stages) then
    for i, v in pairs(self.stages) do
      if v.index == index then
        v.state = 1
        break
      end
    end
  end
  EventManager:GetInstance():Broadcast(EventId.OnDailyMustBuyDataChanged)
  EventManager:GetInstance():Broadcast(EventId.RefreshWelfareRedDot)
end
local ClaimRewardAtStage = function(self, stageId)
  if not stageId then
    return
  end
  SFSNetwork.SendMessage(MsgDefines.DailyMustBuyReward, stageId)
end
local RequestClaimedReward = function(self)
  SFSNetwork.SendMessage(MsgDefines.DailyMustBuyList)
end
local GetMaxScore = function(self)
  if self.maxScore then
    return self.maxScore
  end
  local maxScore = 0
  if not table.IsNullOrEmpty(self.stages) then
    for i, v in pairs(self.stages) do
      if maxScore < v.score then
        maxScore = v.score
      end
    end
  end
  self.maxScore = maxScore
  return maxScore
end
local GetCurScore = function(self)
  local itemId = self:GetItemId()
  local count = DataCenter.ResourceItemDataManager:GetCountByItemId(itemId)
  return count
end
local GetStages = function(self)
  if not self.stages then
    return {}
  end
  return DeepCopy(self.stages)
end
local GetCanGetStageNum = function(self)
  if not self.stages then
    return 0
  end
  local num = 0
  local curScore = DataCenter.DailyMustBuyManager:GetCurScore()
  for i, v in pairs(self.stages) do
    if v.state == 0 and curScore >= v.score then
      num = num + 1
    end
  end
  return num
end
local GetItemId = function(self)
  if not self.itemId then
    self.itemId = LuaEntry.DataConfig:TryGetNum("Daily_must_buy", "k2", 0)
  end
  return self.itemId
end
DailyMustBuyManager.__init = __init
DailyMustBuyManager.__delete = __delete
DailyMustBuyManager.UpdateData = UpdateData
DailyMustBuyManager.AddNewClaimedReward = AddNewClaimedReward
DailyMustBuyManager.ClaimRewardAtStage = ClaimRewardAtStage
DailyMustBuyManager.RequestClaimedReward = RequestClaimedReward
DailyMustBuyManager.GetMaxScore = GetMaxScore
DailyMustBuyManager.GetCurScore = GetCurScore
DailyMustBuyManager.GetStages = GetStages
DailyMustBuyManager.GetCanGetStageNum = GetCanGetStageNum
DailyMustBuyManager.GetItemId = GetItemId
return DailyMustBuyManager
