local this = class("shopManager")
local _rogueGoodsTpl = L_GameTpl:getRogueGoodsTpl()

function this:buyGoods(param, callback)
  L_ShopStore:req_purchaseShopItem(param, function(sData, errCode)
    if errCode == L_Const.errorCode.ErrCodeShopOldVersion then
      local data_tip = {
        txtTitle = L_WordsTpl:getValue("ui_goods_01"),
        txtContent = L_WordsTpl:getValue("ui_goods_02"),
        confirmCallback = function()
          if callback then
            callback()
          end
        end
      }
      L_GameUtil.showCommonTip(data_tip)
    elseif errCode == L_Const.errorCode.ErrCodeSucc then
      local buy_rewards = sData.rewards
      if buy_rewards == nil then
        return
      end
      if callback then
        callback()
      end
      local itemList = buy_rewards.rewards or {}
      if not table.isEmpty(itemList) then
        itemList.forceShow = true
        L_RewardManager:showPage(itemList, buy_rewards.src)
      end
    end
  end)
end

function this:buyGoodsRogue(param, callback)
  L_ShopStore:req_purchaseShopItem(param, function(sData, errCode)
    if errCode == L_Const.errorCode.ErrCodeShopOldVersion then
      local data_tip = {
        txtTitle = L_WordsTpl:getValue("ui_goods_01"),
        txtContent = L_WordsTpl:getValue("ui_goods_02"),
        confirmCallback = function()
          if callback then
            callback()
          end
        end
      }
      L_GameUtil.showCommonTip(data_tip)
    elseif errCode == L_Const.errorCode.ErrCodeSucc and callback then
      callback()
    end
  end)
end

function this:getShopTplEndTime(shopId)
  local shopTpl = L_GameTpl:getShopTpl()
  local tpl = shopTpl:getTplById(shopId)
  local endTime = shopTpl:getEndTime(tpl)
  if string.isEmpty(endTime) then
    return
  end
  return L_TimeUtil.getDateTimeStamp(endTime)
end

return this
