local A=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local p=game:GetService("\080\104\121\115\105\099\115\083\101\114\118\105\099\101")local f=A:WaitForChild("\077\111\100\117\108\101\115")local R=game:GetService("\080\108\097\121\101\114\115")local u=require(f.src.utils.Logger)local K=require(f.src.GhostAbility)local d=game:GetService("\077\097\114\107\101\116\112\108\097\099\101\083\101\114\118\105\099\101")local i="\057\053\052\052\054\052\056"local g="\057\053\054\054\054\052\051"local S={HIGH_JUMP_ID=i,GHOST_MODE_ID=g}function S.addAbility(f,A,p)if A.Character then local f=A.Character local R=f:FindFirstChild("\072\117\109\097\110\111\105\100")if i==p then u:i("\065\100\100\105\110\103 \072\105\103\104 \074\117\109\112 \097\098\105\108\105\116\121 \116\111 \112\108\097\121\101\114")R.JumpPower=100 elseif g==p then u:d("\072\097\115 \103\104\111\115\116 \109\111\100\101")end else u:d("\078\111 \067\104\097\114\097\099\116\101\114 \102\111\117\110\100 \102\111\114 \112\108\097\121\101\114\058"..A.Name)end end function S.hasGamePass(f,A,p)local R=false local K,i=pcall(function()R=d:UserOwnsGamePassAsync(A.UserId,p)end)if not K then u:w("\069\114\114\111\114 \119\104\105\108\101 \099\104\101\099\107\105\110\103 \105\102 \112\108\097\121\101\114 \104\097\115 \112\097\115\115\058 "..tostring(i))return end if R==true then print(A.Name..(" \111\119\110\115 \116\104\101 \103\097\109\101 \112\097\115\115 \119\105\116\104 \073\068 "..p))S:addAbility(A,p)return true end return false end function S.promptPurchase(p,A)local f=R.LocalPlayer local K=false local i,g=pcall(function()K=d:UserOwnsGamePassAsync(f.UserId,A)end)if not i then u:w("\069\114\114\111\114 \119\104\105\108\101 \099\104\101\099\107\105\110\103 \105\102 \112\108\097\121\101\114 \104\097\115 \112\114\111\100\117\099\116\073\100\058 "..tostring(g))return end if K then u:e("\080\108\097\121\101\114 "..(f.Name.." \097\108\114\101\097\100\121 \111\119\110\115 \112\097\115\115"))else d:PromptGamePassPurchase(f,A)end end function S.getGamePass(p,A)local f=d:GetProductInfo(A,Enum.InfoType.GamePass)return{icon="\114\098\120\097\115\115\101\116\105\100\058\047\047"..f.IconImageAssetId;name=f.Name;description=f.Description,price=f.PriceInRobux;isGhost=A==g;isGamePass=true}end return S
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local PhysicsService = game:GetService('PhysicsService')

local Modules = ReplicatedStorage:WaitForChild('Modules')
local Players = game:GetService('Players')
local logger = require(Modules.src.utils.Logger)
local GhostAbility = require(Modules.src.GhostAbility)
local MarketplaceService = game:GetService('MarketplaceService')

local HIGH_JUMP_ID = '9544648'
local GHOST_MODE_ID = '9566643'
local GamePasses = {
	HIGH_JUMP_ID = HIGH_JUMP_ID,
	GHOST_MODE_ID = GHOST_MODE_ID,
}

function GamePasses:addAbility(player, productId)
	if player.Character then
		local char = player.Character
		local humanoid = char:FindFirstChild('Humanoid')
		if HIGH_JUMP_ID == productId then
			logger:i('Adding High Jump ability to player')
			humanoid.JumpPower = 100
		elseif GHOST_MODE_ID == productId then
			logger:d('Has ghost mode')
		end
	else
		logger:d('No Character found for player:' .. player.Name)
	end
end

function GamePasses:hasGamePass(player, productId)
	local hasPass = false

	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, productId)
	end)

	if not success then
		logger:w('Error while checking if player has pass: ' .. tostring(message))
		return
	end

	if hasPass == true then
		print(player.Name .. ' owns the game pass with ID ' .. productId)
		GamePasses:addAbility(player, productId)
		return true
	end
	return false
end

function GamePasses:promptPurchase(productId)
	local player = Players.LocalPlayer
	local hasPass = false

	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, productId)
	end)

	if not success then
		logger:w('Error while checking if player has productId: ' .. tostring(message))
		return
	end

	if hasPass then
		-- Player already owns the game pass; tell them somehow
		logger:e('Player ' .. player.Name .. ' already owns pass')
	else
		MarketplaceService:PromptGamePassPurchase(player, productId)
	end
end

function GamePasses:getGamePass(productId)
	local product = MarketplaceService:GetProductInfo(productId, Enum.InfoType.GamePass)

	return {
		icon = 'rbxassetid://' .. product.IconImageAssetId,
		name = product.Name,
		description = product.Description,
		price = product.PriceInRobux,
		isGhost = (productId == GHOST_MODE_ID),
		isGamePass = true,
	}
end

return GamePasses