local LWSoundTemplateManager = BaseClass("LWSoundTemplateManager")
local LWSoundTemplate = require("DataCenter.LWSound.LWSoundTemplate")
local LWAudioMixerGroupTemplate = require("DataCenter.LWSound.LWAudioMixerGroupTemplate")
local NoTemplate = "NoTemplate"
local __init = function(self)
  self.templateDict = {}
  self.groupInited = false
  self.groupTemplateDict = {}
end
local __delete = function(self)
  self.templateDict = nil
  self.groupTemplateDict = nil
  self.groupInited = nil
end
local GetTemplate = function(self, id)
  id = tonumber(id)
  if id == nil then
    return nil
  end
  if self.templateDict[id] == NoTemplate then
    return nil
  end
  if self.templateDict[id] ~= nil then
    return self.templateDict[id]
  end
  local line = LocalController:instance():getLine(TableName.LW_Sound, id)
  if line ~= nil then
    local template = LWSoundTemplate.New()
    template:InitData(line)
    self.templateDict[id] = template
    return template
  else
    self.templateDict[id] = NoTemplate
    return nil
  end
end
local LoadGroupTemplates = function(self)
  self.groupInited = true
  LocalController:instance():visitTable(TableName.LW_Sound_AudioMixer_Group, function(_, lineData)
    local template = LWAudioMixerGroupTemplate.New()
    template:InitData(lineData)
    self.groupTemplateDict[template.group] = template
  end)
end
local GetGroupTempByName = function(self, name)
  if not self.groupInited then
    self:LoadGroupTemplates()
  end
  if self.groupTemplateDict[name] ~= nil then
    return self.groupTemplateDict[name]
  end
end
local GetGroupTemplates = function(self)
  if not self.groupInited then
    self:LoadGroupTemplates()
  end
  return self.groupTemplateDict
end
LWSoundTemplateManager.__init = __init
LWSoundTemplateManager.__delete = __delete
LWSoundTemplateManager.LoadGroupTemplates = LoadGroupTemplates
LWSoundTemplateManager.GetTemplate = GetTemplate
LWSoundTemplateManager.GetGroupTempByName = GetGroupTempByName
LWSoundTemplateManager.GetGroupTemplates = GetGroupTemplates
return LWSoundTemplateManager
