local RechargeManager = BaseClass("RechargeManager")
local RechargeTemplate = require("DataCenter.Recharge.RechargeTemplate")
local Localization = CS.GameEntry.Localization

function RechargeManager:__init()
  self.rechargeDatas = {}
  self.splitedPara1s = {}
  self.hasInitAllLine = false
  self.actMap = {}
end

function RechargeManager:__delete()
  self.rechargeDatas = nil
  self.splitedPara1s = nil
  self.hasInitAllLine = false
  self.actMap = nil
end

function RechargeManager:GetLine(id)
  if not id then
    return nil
  end
  local data = self.rechargeDatas[tonumber(id)]
  if not data then
    data = LocalController:instance():getLine(TableName.Recharge, id)
    if data then
      local template = RechargeTemplate.New()
      template:InitData(data)
      self.rechargeDatas[tonumber(id)] = template
    end
  end
  return data
end

function RechargeManager:InitAllLines()
  local tableName = TableName.Recharge
  LocalController:instance():visitTable(tableName, function(id, lineData)
    if not self.rechargeDatas[tonumber(id)] then
      local template = RechargeTemplate.New()
      template:InitData(lineData)
      self.rechargeDatas[tonumber(id)] = template
    end
  end)
end

function RechargeManager:GetAllLines()
  if not self.hasInitAllLine then
    self:InitAllLines()
    self.hasInitAllLine = true
  end
  return self.rechargeDatas
end

function RechargeManager:getStrValue(id, key)
  local line = self:GetLine(id)
  if not line then
    return ""
  end
  return line[key]
end

function RechargeManager:GetSplitedPara1(id, sep)
  if not self.splitedPara1s[id] then
    local para1 = self:getStrValue(id, "para1")
    if para1 then
      local _sep = sep or "|"
      self.splitedPara1s[id] = string.split(para1, _sep)
    end
  end
  return self.splitedPara1s[id]
end

return RechargeManager
