local this = {}

function this:startDebugBattle(isAutoBattle)
  if not self._ESetMainControlHandler then
    self._ESetMainControlHandler = handler(self, self.startDebugBattleNoTeam)
    AzurWorld.playerMgr:RegisterEvent(C_EPlayerEvent.ESetMainControl, self._ESetMainControlHandler)
  end
  local playerEntity = L_PlayerManager:getMainControlEntity()
  local pos = playerEntity:getPosition()
  L_CameraManager:bindPoint(pos)
  AzurWorld.playerMgr.myPlayerUnitAdapter.isCustom = true
  AzurWorld.playerMgr.myPlayerUnitAdapter.isAutoFight = isAutoBattle
  AzurWorld.playerMgr.myPlayerUnitAdapter:SwitchToFormationMainControl()
end

function this:startDebugBattleNoTeam()
  if self._ESetMainControlHandler then
    AzurWorld.playerMgr:UnregisterEvent(C_EPlayerEvent.ESetMainControl, self._ESetMainControlHandler)
    self._ESetMainControlHandler = nil
  end
  self.battleFieldDataEntity = require("modules.battle.data.battleFieldDataEntity").new()
  self.battleFieldDataEntity:setBattleType(C_EBattlerType.DebugBattle)
  self.battleFieldDataEntity:setMonsterCreateDataList(self:getDebugEnemyList())
  self:doFsmBattleField()
end

function this:getDebugEnemyList()
  local enemyDic = L_BattleEnemyStore:getEnemyDic()
  local enemyList = {}
  for i, v in pairs(enemyDic) do
    table.insert(enemyList, v)
  end
  local playerEntity = L_PlayerManager:getMainControlEntity()
  local pos = playerEntity:getPosition()
  local rot = playerEntity:getRotation()
  local posList = {}
  for i = 1, 20 do
    local setPosInfo = L_BattleEnemyStore:createEnemySetInfo(i, pos + L_Vector3.new(0, 0, 2 * i), rot)
    table.insert(posList, setPosInfo)
  end
  local createList = {}
  for i, v in ipairs(enemyList) do
    local createEnemyData = C_EntityManager.CreateMonsterData()
    createEnemyData.guid = v.guid
    createEnemyData.configID = v.enemyId
    createEnemyData.lv = v.lv
    createEnemyData.position = posList[i].pos
    createEnemyData.rotation = Unity.Quaternion.Euler(posList[i].rot)
    createEnemyData.campType = CS.Lens.Gameplay.Modules.BigWorld.ECampType.Monster
    table.insert(createList, createEnemyData)
  end
  return createList
end

return this
