local CityRebuildDataManager = BaseClass("CityRebuildDataManager")
local POP_DELAY_TIME = 4
local __init = function(self)
  self.reward = nil
  self.allianceInfo = {}
  self.march = {}
  self.rewardCfg = {}
  self:AddListener()
end
local __delete = function(self)
  if self.delayTime then
    self.delayTime:Stop()
    self.delayTime = nil
  end
  self.reward = nil
  self.allianceInfo = nil
  self.march = nil
  self.create = nil
  self.hasCure = nil
  self.rewardCfg = nil
  self:RemoveListener()
end
local StartUp = function(self)
end
local AddListener = function(self)
end
local RemoveListener = function(self)
end
local SetAllianceAndMarchInfo = function(self, message)
  local errCode = message.errorCode
  if errCode ~= nil then
    UIUtil.ShowTipsId(errCode)
  else
    if message.alliance then
      self.allianceInfo = message.alliance
      local alliance = AllianceBaseInfo.New()
      alliance:ParseData(message.alliance, false)
      if alliance.uid ~= nil and alliance.uid ~= "" then
        self.allianceInfo = alliance
      end
    end
    if message.march then
      self.march = message.march
    end
  end
  if self.create then
    self.delayTime = TimerManager:GetInstance():DelayInvoke(function()
      UIManager:GetInstance():OpenWindow(UIWindowNames.LWUICityRebuildNewView, {
        anim = true,
        UIMainAnim = UIMainAnimType.AllHide
      })
    end, POP_DELAY_TIME)
  end
end
local SetRebuildRewardInfo = function(self, message)
  local errCode = message.errorCode
  if errCode ~= nil then
    UIUtil.ShowTipsId(errCode)
  else
    if message.reward then
      self.reward = message.reward
      DataCenter.RewardManager:AddRewardsAndRes(message)
    end
    if message.hasCure then
      self.hasCure = message.hasCure
    end
  end
end
local GetAllianceInfoInfo = function(self)
  return self.allianceInfo
end
local ReleaseAllianceInfoInfo = function(self)
  self.allianceInfo = nil
end
local GetRebuildRewardInfo = function(self)
  return DataCenter.RewardManager:ReturnRewardParamForMessage(self.reward)
end
local CheckCanPopRebuildUI = function(self)
  if self.reward and #self.reward > 0 then
    return true
  end
  return false
end
local SetRebuildRewardInfoNull = function(self)
  self.reward = nil
end
local GetMarchInfo = function(self)
  return self.march
end
local GetCureState = function(self)
  if self.hasCure then
    return self.hasCure
  else
    return false
  end
end
local SetFlyRewardData = function(self, cfg)
  self.rewardCfg = cfg
end
local FlyReward = function(self)
  local window = UIManager:GetInstance():GetWindow(UIWindowNames.UIMain)
  if window and window.Ctrl:IsVisible() and self.rewardCfg then
    EventManager:GetInstance():Broadcast(EventId.UIMainFlyReward, self.rewardCfg)
  end
end
local SendMarchMessage = function(self, create)
  self.create = create
  SFSNetwork.SendMessage(MsgDefines.AllianceRescueCreateMarch, create)
end
local SendStopCityFireMessage = function(self)
  SFSNetwork.SendMessage(MsgDefines.AllianceRescueStopCityFire)
end
CityRebuildDataManager.__init = __init
CityRebuildDataManager.__delete = __delete
CityRebuildDataManager.StartUp = StartUp
CityRebuildDataManager.AddListener = AddListener
CityRebuildDataManager.RemoveListener = RemoveListener
CityRebuildDataManager.SetRebuildRewardInfo = SetRebuildRewardInfo
CityRebuildDataManager.GetRebuildRewardInfo = GetRebuildRewardInfo
CityRebuildDataManager.SendMarchMessage = SendMarchMessage
CityRebuildDataManager.SetAllianceAndMarchInfo = SetAllianceAndMarchInfo
CityRebuildDataManager.SendStopCityFireMessage = SendStopCityFireMessage
CityRebuildDataManager.GetAllianceInfoInfo = GetAllianceInfoInfo
CityRebuildDataManager.GetMarchInfo = GetMarchInfo
CityRebuildDataManager.SetRebuildRewardInfoNull = SetRebuildRewardInfoNull
CityRebuildDataManager.CheckCanPopRebuildUI = CheckCanPopRebuildUI
CityRebuildDataManager.ReleaseAllianceInfoInfo = ReleaseAllianceInfoInfo
CityRebuildDataManager.GetCureState = GetCureState
CityRebuildDataManager.SetFlyRewardData = SetFlyRewardData
CityRebuildDataManager.FlyReward = FlyReward
return CityRebuildDataManager
