local this = class("battleFormationStore", G_BaseStore)
this.event = {}
this:importPartialClass(require(L_R.store .. "battleEnemy.battleEnemyState"))

function this:createEnemyItem(id, lv)
  self.data.curGuid = self.data.curGuid + 1
  local battleEnemyItem = require(L_R.store .. "battleEnemy.data.battleEnemyItem").new()
  battleEnemyItem.guid = self.data.curGuid
  battleEnemyItem.enemyId = id
  battleEnemyItem.lv = lv
  self.data.enemyDic[self.data.curGuid] = battleEnemyItem
  return battleEnemyItem
end

function this:deleteEnemyItem(guid)
  self.data.enemyDic[guid] = nil
end

function this:setEnemyData(battleEnemyItem, setPosInfo)
  for i, v in ipairs(setPosInfo) do
    if battleEnemyItem[i] then
      battleEnemyItem[i].setPosInfo = v
    end
  end
  return battleEnemyItem
end

function this:createEnemySetInfo(index, pos, rot)
  local battleSetPosInfo = require(L_R.store .. "battleEnemy.data.battleSetPosInfo").new()
  battleSetPosInfo.index = index
  battleSetPosInfo.pos = pos
  battleSetPosInfo.rot = rot
  return battleSetPosInfo
end

function this:resetEnemySetInfo()
  for i, v in pairs(self.data.enemyDic) do
    v.setPosInfo = nil
  end
end

function this:saveCurEnemy(index)
  local info = self:getEnemyDic()
  local list = {}
  for i, v in pairs(info) do
    local data = CS.Lens.Gameplay.Modules.BigWorld.Tools.Utility.BattleEnemyConfigData()
    data.guid = v.guid
    data.enemyId = v.enemyId
    data.lv = v.lv
    table.insert(list, data)
  end
  C_BattleDebugLuaUtility.SaveDebugLua(list, string.format("battle_editor_%s.bytes", index), "../Client/Assets/ResourcesAssets/Config/World/Home/")
end

function this:loadEnemy(index)
  local path = string.format("../Client/Assets/ResourcesAssets/Config/World/Home/battle_editor_%s.bytes", index)
  if C_BattleDebugLuaUtility.IsLuaExists(path) then
    path = string.format("Config/World/Home/battle_editor_%s.bytes", index)
    local cfg = L_CommonUtil.getTextToLua(path)
    return cfg
  end
  return {}
end

function this:resetLoadEnemy(index)
  local path = string.format("../Client/Assets/ResourcesAssets/Config/World/Home/battle_editor_%s.bytes", index)
  if not C_BattleDebugLuaUtility.IsLuaExists(path) then
    self.data.enemyDic = {}
    return
  end
  self.data.enemyDic = {}
  path = string.format("Config/World/Home/battle_editor_%s.bytes", index)
  local cfg = L_CommonUtil.getTextToLua(path)
  for i, v in pairs(cfg) do
    local battleEnemyItem = require(L_R.store .. "battleEnemy.data.battleEnemyItem").new()
    battleEnemyItem.guid = v.guid
    battleEnemyItem.enemyId = v.enemyId
    battleEnemyItem.lv = v.lv
    self.data.enemyDic[v.guid] = battleEnemyItem
  end
end

function this:loadEnemyInfoDic()
  local dic = {}
  for i = 1, 5 do
    dic[i] = self:loadEnemy(i)
  end
  return dic
end

return this
