local this = {}

function this:req_useItem(data, callback)
  L_Net:sendMessage(MsgGenCode.CSProtoUseItem, data, function(rspData, errorCode)
    callback(rspData, errorCode)
  end)
end

function this:req_CSProtoExchangeItem(data, callback)
  L_Net:sendMessage(MsgGenCode.CSProtoExchangeItem, data, function(rspData, errorCode)
    callback(rspData, errorCode)
  end)
end

function this:rsp_syncBagInfo(info)
  local items = info.items or {}
  local existNew = false
  for _, v in ipairs(items) do
    if v.itemnum < 1 then
      local dto = self:getItem(v.itemid)
      if dto then
        dto.itemNum = v.itemnum
        dto.deadTime = v.deadtime
        dto.exts = v.exts
        dto.itemType = v.itemtype
        self:removeItem(v.itemid)
      end
    else
      local dto, isNew = self:getItem(v.itemid, true)
      dto.itemNum = v.itemnum
      dto.deadTime = v.deadtime
      dto.exts = v.exts
      dto.itemType = v.itemtype
      if isNew then
        existNew = true
        if self.isInit then
          dto.isNew = true
          self.data.newItemDic[dto.itemID] = dto
        end
      end
    end
  end
  self.isInit = true
  self:call(self.event.refreshBag, items, existNew)
end

function this:rsp_syncMountSnackBag(data)
  for i, v in pairs(data) do
    self.data.mountSnackBag[v.guid] = v
  end
  self:call(self.event.refreshMountSnackBag)
end

return this
