local GovernmentTemplateManager = BaseClass("GovernmentTemplateManager")
local GovernmentTemplate = require("DataCenter.GovernmentManager.GovernmentTemplate")
local __init = function(self)
  self.templateDic = nil
end
local __delete = function(self)
  self.templateDic = nil
end
local InitAllTemplate = function(self)
  self.templateDic = {}
  LocalController:instance():visitTable(TableName.Government, function(id, lineData)
    local item = GovernmentTemplate.New()
    item:InitData(lineData)
    self.templateDic[tostring(item.id)] = item
  end)
end
local GetAllTemplate = function(self)
  if self.templateDic == nil then
    self:InitAllTemplate()
  end
  return self.templateDic
end
local GetTemplate = function(self, id)
  if self.templateDic == nil then
    self:InitAllTemplate()
  end
  return self.templateDic[tostring(id)]
end

function GovernmentTemplateManager:GetTemplateByOrder(order)
  if self.templateDic == nil then
    self:InitAllTemplate()
  end
  for _, v in pairs(self.templateDic) do
    if v ~= nil and v.order == order then
      return v
    end
  end
  return nil
end

function GovernmentTemplateManager:GetTemplateByTitleName(titleName)
  if self.templateDic == nil then
    self:InitAllTemplate()
  end
  for _, v in pairs(self.templateDic) do
    if v ~= nil and v.title_name == titleName then
      return v
    end
  end
  return nil
end

local IsConqueror = function(self, id)
  local template = self:GetTemplate(id)
  return template and template.type == 1
end

function GovernmentTemplateManager:GetTemplateName(id)
  local template = self:GetTemplate(id)
  if template ~= nil then
    return CS.GameEntry.Localization:GetString(template.name)
  end
  return ""
end

GovernmentTemplateManager.__init = __init
GovernmentTemplateManager.__delete = __delete
GovernmentTemplateManager.InitAllTemplate = InitAllTemplate
GovernmentTemplateManager.GetAllTemplate = GetAllTemplate
GovernmentTemplateManager.GetTemplate = GetTemplate
GovernmentTemplateManager.IsConqueror = IsConqueror
return GovernmentTemplateManager
