local FSM = BaseClass("FSM")
local Init = function(self)
  self.states = {}
  self.curStateIndex = -1
end
local __init = function(self)
  self:Init()
end
local __delete = function(self)
  if self.states then
    for _, v in pairs(self.states) do
      v:Delete()
    end
    self.states = nil
  end
  self.curStateIndex = nil
end
local AddState = function(self, stateIndex, state)
  if self.states[stateIndex] then
    Logger.LogError("\231\138\182\230\128\129\233\135\141\229\164\141\239\188\154stateEnum")
  else
    self.states[stateIndex] = state
  end
end
local GetStateIndex = function(self)
  return self.curStateIndex
end
local GetCurState = function(self)
  return self.states[self.curStateIndex]
end
local ChangeState = function(self, stateIndex, ...)
  if self.curStateIndex == stateIndex then
    if self.states[self.curStateIndex].OnTransToSelf then
      self.states[self.curStateIndex]:OnTransToSelf(...)
    end
    return
  end
  if self.curStateIndex > -1 then
    self.states[self.curStateIndex]:OnExit()
  end
  self.curStateIndex = stateIndex
  self.states[stateIndex]:OnEnter(...)
end
local OnUpdate = function(self, ...)
  if self.curStateIndex > -1 then
    self.states[self.curStateIndex]:OnUpdate(...)
  end
end
local HandleInput = function(self, ...)
  if self.curStateIndex > -1 then
    self.states[self.curStateIndex]:HandleInput(...)
  end
end
FSM.Init = Init
FSM.__init = __init
FSM.__delete = __delete
FSM.AddState = AddState
FSM.GetStateIndex = GetStateIndex
FSM.ChangeState = ChangeState
FSM.OnUpdate = OnUpdate
FSM.HandleInput = HandleInput
FSM.GetCurState = GetCurState
return FSM
