local this = class("worldSubroleTpl")

function this:init(config)
  self.sceneDic = {}
  for _, v in pairs(config) do
    local tab = self.sceneDic[v.cityId]
    if tab == nil then
      tab = {}
      self.sceneDic[v.cityId] = tab
    end
    if v.roleId ~= 0 then
      tab[v.roleId] = v
    else
      if tab.default == nil then
        tab.default = {}
      end
      table.insert(tab.default, v)
    end
  end
end

function this:getTplByRoleId(cityId, roleId)
  local city = self.sceneDic[cityId]
  if city then
    local tpl = city[roleId]
    return tpl
  end
end

function this:getDefaultTpl(cityId, index)
  local city = self.sceneDic[cityId]
  if city then
    local count = #city.default
    local index = index % count
    index = index == 0 and count or index
    local tpl = city.default[index]
    return tpl
  end
end

function this:getDefaultTplByCityId(cityId)
  local city = self.sceneDic[cityId]
  return city and city.default
end

function this:getId(tpl)
  return tpl.id
end

function this:getBehaviorTaskId(tpl)
  return tpl.behaviorTaskId
end

function this:getRoleType(tpl)
  return tpl.roleType
end

function this:getCityId(tpl)
  return tpl.cityId
end

function this:getBehavior(tpl)
  return tpl.behavior
end

function this:getRoleId(tpl)
  return tpl.roleId
end

return this
