local this = {}
local spTpl = L_GameTpl:getSpiritronTpl()

function this:req_CSProtoLiZiStoryRecored(configId, callback)
  if L_SpiritronStore:isSpiritStoryPlayed(configId) then
    if callback then
      callback()
    end
    return
  end
  L_Net:sendMessage(MsgGenCode.CSProtoLiZiStoryRecored, {cfg_id = configId}, function(rspData, errorCode)
    if errorCode ~= L_Const.errorCode.ErrCodeSucc then
      return
    end
    table.insert(self.data.spiritStoryList, configId)
    self:call(self.event.spiritStoryRefresh)
    if callback then
      callback()
    end
  end)
end

function this:req_equipSpiritron(heroId, guid, callback)
  local data = {hero_id = heroId, guid = guid}
  L_Net:sendMessage(MsgGenCode.CSProtoMoveSpiritron, data, function()
    if callback then
      callback()
    end
    self:call(self.event.switchSpirit, {heroGuid = heroId, spiritGuid = guid})
  end)
end

function this:req_composeSpiritron(param, callback)
  if L_BattleDataManager:checkPlayerBattle() then
    L_FlyMsgManager:showNormalMsg(L_BattleDataManager:getBattleBlockTips(L_Const.BattleBlockType.SpiritStrength))
    return
  end
  local data = param
  L_Net:sendMessage(MsgGenCode.CSProtoComposeSpiritron, data, function(sData, errorCode)
    callback(sData, errorCode)
    if sData.rewards then
      local data = sData.rewards
      data.title = L_WordsTpl:getValue("notice_spiritronStore")
      L_RewardManager:showPage(data, sData.src)
    end
  end)
end

function this:req_risingStarSpiritron(param, callback)
  if L_BattleDataManager:checkPlayerBattle() then
    L_FlyMsgManager:showNormalMsg(L_BattleDataManager:getBattleBlockTips(L_Const.BattleBlockType.SpiritStrength))
    return
  end
  local data = param
  L_Net:sendMessage(MsgGenCode.CSProtoRisingStarSpiritron, data, callback)
end

function this:req_lockSpiritron(guid, callback)
  local item = self:getSpiritronItem(guid)
  local data = {
    guid = item.guid,
    lock = not item.lock
  }
  self:call(self.event.spiritLockChange, {spiritGuid = guid})
  L_Net:sendMessage(MsgGenCode.CSProtoSetLockSpiritron, data, function()
    if callback then
      callback()
    end
    self:call(self.event.spiritLockStatusChange, {spiritGuid = guid})
  end)
end

function this:req_rankUpSpiritron(guid, callback)
  if L_BattleDataManager:checkPlayerBattle() then
    L_FlyMsgManager:showNormalMsg(L_BattleDataManager:getBattleBlockTips(L_Const.BattleBlockType.SpiritStrength))
    return
  end
  local data = {guid = guid}
  L_Net:sendMessage(MsgGenCode.CSProtoRankUpSpiritron, data, function(rspData, errorCode)
    if callback then
      callback()
    end
  end)
end

function this:rsp_syncSpiritron(info, isInit)
end

return this
