local AllianceAutoInviteManager = BaseClass("AllianceAutoInviteManager")
local Startup = function()
end
local __init = function(self)
  self.autoInviteList = {}
  self.unreadCount = 0
  self:AddListener()
end
local AddListener = function(self)
end
local RemoveListener = function(self)
end
local __delete = function(self)
  self.autoInviteList = nil
  self.unreadCount = nil
end
local GetInviteInfoReq = function(self)
  SFSNetwork.SendMessage(MsgDefines.GetAllianceAutoInviteInfo)
end
local AcceptAllianceAutoInviteReq = function(self, allianceId)
  SFSNetwork.SendMessage(MsgDefines.AcceptAllianceAutoInvite, allianceId)
end
local UpdateAutoInviteList = function(self, t)
  if not t.inviteArr then
    return
  end
  self.autoInviteList = {}
  for i, v in ipairs(t.inviteArr) do
    local newAutoInvite = AllianceAutoInviteData.New()
    newAutoInvite:ParseData(v)
    table.insert(self.autoInviteList, newAutoInvite)
  end
  self.unreadCount = #self.autoInviteList
  EventManager:GetInstance():Broadcast(EventId.OnGetNewAllianceAutoInvite)
end
local UpdateOneAutoInvite = function(self, t)
  local newAutoInvite = AllianceAutoInviteData.New()
  newAutoInvite:ParseData(t)
  table.insert(self.autoInviteList, newAutoInvite)
  self.unreadCount = self.unreadCount + 1
  EventManager:GetInstance():Broadcast(EventId.OnGetNewAllianceAutoInvite)
end
local ResetUnreadCount = function(self)
  self.unreadCount = 0
end
local GetUnreadCount = function(self)
  return self.unreadCount
end
local GetAutoInviteList = function(self)
  local retList = {}
  for i, v in ipairs(self.autoInviteList) do
    if v:CheckIfIsValid() then
      table.insert(retList, v)
    end
  end
  return retList
end
local CheckIfNeedAutoInviteChatRoom = function(self)
  local tempList = self:GetAutoInviteList()
  return tempList and 0 < #tempList
end
local TryClearAllInvites = function(self)
  local tempList = self:GetAutoInviteList()
  if tempList and 0 < #tempList then
    local curAlId = LuaEntry.Player.allianceId
    for i, v in ipairs(tempList) do
      if v.allianceId == curAlId then
        self:ClearAllInvite()
        break
      end
    end
  end
end
local ClearAllInvite = function(self)
  self.autoInviteList = {}
  self.unreadCount = 0
  EventManager:GetInstance():Broadcast(EventId.OnGetNewAllianceAutoInvite)
end
AllianceAutoInviteManager.Startup = Startup
AllianceAutoInviteManager.__init = __init
AllianceAutoInviteManager.__delete = __delete
AllianceAutoInviteManager.AddListener = AddListener
AllianceAutoInviteManager.RemoveListener = RemoveListener
AllianceAutoInviteManager.GetInviteInfoReq = GetInviteInfoReq
AllianceAutoInviteManager.AcceptAllianceAutoInviteReq = AcceptAllianceAutoInviteReq
AllianceAutoInviteManager.UpdateAutoInviteList = UpdateAutoInviteList
AllianceAutoInviteManager.UpdateOneAutoInvite = UpdateOneAutoInvite
AllianceAutoInviteManager.GetAutoInviteList = GetAutoInviteList
AllianceAutoInviteManager.CheckIfNeedAutoInviteChatRoom = CheckIfNeedAutoInviteChatRoom
AllianceAutoInviteManager.ClearAllInvite = ClearAllInvite
AllianceAutoInviteManager.ResetUnreadCount = ResetUnreadCount
AllianceAutoInviteManager.GetUnreadCount = GetUnreadCount
AllianceAutoInviteManager.TryClearAllInvites = TryClearAllInvites
return AllianceAutoInviteManager
