local this = class("wardrobeAvatarTpl")

function this:init(config)
  self.data = config
  self._useType = {}
  self._useTypeList = L_Config:getConfig("game", "AVATAR_TYPE")
  for _, type in ipairs(self._useTypeList) do
    self._useType[type] = true
  end
end

function this:getTplById(id)
  return self.data[id] or {}
end

function this:getDesc(tpl)
  return tpl.desc
end

function this:getHeight(tpl)
  return tpl.height
end

function this:getSex(tpl)
  return tpl.sex
end

function this:getInitial(tpl)
  return tpl.initial
end

function this:getHeightName(tpl)
  return L_Config:provider(tpl.heightName)
end

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

function this:getType(tpl)
  return tpl.type
end

function this:getColorId(tpl)
  return tpl.colorId or {}
end

function this:getIcon(tpl)
  return tpl.icon
end

function this:getFirstColorName(tpl)
  local colorId = tpl.colorId[1] and tpl.colorId[1][1]
  if colorId then
    local colorTpl = L_GameTpl:getWardrobeColorTpl()
    local colorConf = colorTpl:getTplById(colorId)
    return colorTpl:getName(colorConf)
  end
end

function this:getWardrobeId(tpl)
  return tpl.wardrobeId
end

function this:getIdByWardrobeId(wardrobeId)
  for id, conf in pairs(self.data) do
    if conf.wardrobeId == wardrobeId then
      return id
    end
  end
end

function this:getAllAvatarIdByType(type, sex)
  local res = {}
  for id, conf in pairs(self.data) do
    if conf.type == type and conf.sex == sex then
      table.insert(res, id)
    end
  end
  table.sort(res)
  return res
end

function this:isTypeUse(type)
  return self._useType[type]
end

function this:getTypeList()
  return self._useTypeList
end

return this
