local this = class("battleFieldTpl")
local path = "Config/Battle/BattleField/ast_battleField_%s.asset"

function this:init()
  self.data = {}
end

function this:getTplById(id)
  if not self.data[id] then
    local path = string.format(path, tostring(id))
    local config = C_LuaUtility.LoadBattleConfig(path).config
    local tpl = {}
    tpl.itemInfos = {}
    for i = 0, config.battleField.itemInfos.Count - 1 do
      table.insert(tpl.itemInfos, config.battleField.itemInfos[i])
    end
    tpl.slotInfos = {}
    for i = 0, config.battleField.slotInfos.Count - 1 do
      table.insert(tpl.slotInfos, config.battleField.slotInfos[i])
    end
    tpl.enemyInfos = {}
    for i = 0, config.battleField.enemyInfos.Count - 1 do
      table.insert(tpl.enemyInfos, config.battleField.enemyInfos[i])
    end
    self.data[id] = tpl
  end
  return self.data[id]
end

function this:getSlotInfos(tpl)
  return tpl.slotInfos
end

function this:getItemInfos(tpl)
  return tpl.itemInfos
end

function this:getEnemyInfos(tpl)
  return tpl.enemyInfos
end

function this:getEnemyInfoByGuid(tpl, guid)
  if table.isEmpty(tpl.enemyInfos) then
    return nil
  end
  for i, v in ipairs(tpl.enemyInfos) do
    if v.guid == guid then
      return v
    end
  end
  return nil
end

function this:getEnemyListByGroupId(tpl, groupId)
  local allEnemy = self:getEnemyInfos(tpl)
  local enemyList = {}
  for i, v in ipairs(allEnemy) do
    if v.unitGroupId == groupId then
      table.insert(enemyList, v)
    end
  end
  return enemyList
end

function this:getSlotInfoList(battleId)
  local tpl = L_GameTpl:getBattleFieldTpl():getTplById(battleId)
  local itemInfos = L_GameTpl:getBattleFieldTpl():getSlotInfos(tpl)
  return itemInfos
end

return this
