local CommerceManager = class("CommerceManager", BaseModule)

-- 体力

function CommerceManager:showBuyVitUI()
	UIManager:showUI("app/ui/commerce/buy_vit_ui")
end

function CommerceManager:onBuyVit(isFree)
	local responseData = {
		energy_limit = {
			diamond_count = 0,
			ad_count = 0
		}
	}
	if isFree then
		local reward = ConfigManager:getConfig("const")["stamina_ad_buy"].reward
		responseData.rewards = {reward}
		self:sendMessage(ProtoMsgType.FromMsgEnum.EnergyByADReq, {}, responseData, self.onBuyBitFinish, BIReport.ITEM_GET_TYPE.ADS_BUY_VIT)
	else
		local reward = ConfigManager:getConfig("const")["stamina_diamond_buy"].reward
		responseData.rewards = {reward}
		local cost = ConfigManager:getConfig("const")["stamina_diamond_cost"].reward
		responseData.costs = {cost}
		self:sendMessage(ProtoMsgType.FromMsgEnum.EnergyByDiamondReq, {}, responseData, self.onBuyBitFinish, BIReport.ITEM_GET_TYPE.GEM_BUY_VIT)
	end
end

function CommerceManager:onBuyBitFinish(data)
	if data.status ~= 0 then
		return
	end
	if data.costs then -- 钻石购买
		DataManager.PlayerData:addVitGemBuyCount()
	else -- 激励视频
		DataManager.PlayerData:addVitAdBuyCount()
	end
	if data.rewards then
		GFunc.showRewardBox(data.rewards)
	end
end

-- 竞技场入场券

function CommerceManager:showBuyArenaTicketUI()
	UIManager:showUI("app/ui/arena/arena_buy_ticket_ui")
end

function CommerceManager:onBuyArenaTicket(isAd)
	local report = nil
	if isAd then
		report = BIReport.ITEM_GET_TYPE.ADS_BUY_ARENA_TICKET
	else
		report = BIReport.ITEM_GET_TYPE.GEM_BUY_ARENA_TICKET
	end
	self:sendMessage(ProtoMsgType.FromMsgEnum.BuyTicketReq, {ad = isAd}, {}, self.onBuyArenaTicketFinish, report)
end

function CommerceManager:onBuyArenaTicketFinish(data)
	if data.status ~= 0 then
		return
	end

	if data.reqData and data.reqData.ad then
		-- 激励视频
		DataManager.PlayerData:addArenaTicketAdBuyCount()
	else
		-- 钻石购买
		DataManager.PlayerData:addArenaTicketGemBuyCount()
	end
	if data.rewards then
		GFunc.showRewardBox(data.rewards)
	end
end

return CommerceManager