local this = {}

function this:init()
  this.super.init(self)
  self.data = {
    itemDic = {},
    newItemDic = {},
    mountSnackBag = {}
  }
end

function this:getAllItem()
  return self.data.itemDic
end

function this:getAllItemListInBag()
  local all = table.findAll(self:getAllItem(), function(v)
    local item = L_ItemManager:parseCommonItem(v.itemID)
    return item.inBag
  end)
  return all
end

function this:getAllItemListInBagByTag(bagType, bagSubType)
  local commonItemTpl = L_GameTpl:getCommonItemTpl()
  local all = table.findAll(self:getAllItem(), function(v)
    local tpl = commonItemTpl:getTplById(v.itemID)
    if not tpl then
      return false
    end
    local inBag = commonItemTpl:getInBag(tpl)
    local type = commonItemTpl:getBagType(tpl)
    local subType = commonItemTpl:getBagSubType(tpl)
    if not math.isEmpty(bagSubType) then
      return inBag and type == bagType and subType == bagSubType
    else
      return inBag and type == bagType
    end
  end)
  return all
end

function this:getItem(itemId, isCreate)
  local item = self.data.itemDic[itemId]
  if item == nil and isCreate then
    item = require(L_R.store .. "bag.bagItem").new()
    item.itemID = itemId
    self.data.itemDic[itemId] = item
    return item, true
  else
    return item
  end
end

function this:getItemNum(itemId)
  local item = self:getItem(itemId)
  return item and item.itemNum or 0
end

return this
