local this = {}

function this:req_setStandee(id, callback)
  local cur = self:getCurStandeeInfo()
  local data = {
    backboard = cur.backboard,
    baseboard = cur.baseboard,
    pet_accessory = cur.pet_accessory,
    role = table.clone(cur.role)
  }
  local type = self._playerCardDressTpl:getTplById(id).type
  if type == L_Const.playerDressType.backboard then
    data.backboard = id
  elseif type == L_Const.playerDressType.baseboard then
    data.baseboard = id
  elseif type == L_Const.playerDressType.hero then
    if data.role == nil then
      data.role = {}
    end
    data.role.config = id
    local item = self:getItem(id)
    data.role.url = item.url
  elseif type == L_Const.playerDressType.pet then
    data.pet_accessory = id
  end
  L_Net:sendMessage(MsgGenCode.CSProtoChangeStandPlates, data, function(rspData, errorCode)
    if errorCode == 0 and callback then
      if type == L_Const.playerDressType.backboard then
        cur.backboard = id
      elseif type == L_Const.playerDressType.baseboard then
        cur.baseboard = id
      elseif type == L_Const.playerDressType.hero then
        cur.role.config = id
        local item = self:getItem(id)
        cur.role.url = item.url
      elseif type == L_Const.playerDressType.pet then
        cur.pet_accessory = id
      end
      callback()
    end
  end)
end

function this:req_setCustomHeroSlot(data, callback)
  L_Net:sendMessage(MsgGenCode.CSProtoSetStandPlatesRole, data, function(rspData, errorCode)
    if errorCode == 0 and callback then
      callback()
    end
  end)
end

function this:rsp_syncPlayerDisplayItem(data)
  if data.bags ~= nil then
    for _, v in pairs(data.bags) do
      local id = v.config
      if self.data.setHasInitSync and not self:getItem(id) then
        L_ReddotManager:markNew(L_ReddotManager.DotDef.PlayerDressItem, id, true)
      end
      local url = v.url
      local item = self:getItem(id, true)
      local tpl = self._playerCardDressTpl:getTplById(id)
      if item and tpl then
        item.id = id
        item.url = url
        item.tpl = tpl
      end
      if self.data.setHasInitSync then
        self:call(self.event.dressItemSync, id)
      end
    end
    self:fillEmptyCustom()
    self.data.setHasInitSync = true
  else
    self:clear()
  end
end

return this
