local A=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local v=A:WaitForChild("\099\111\109\109\111\110")local Y=A:WaitForChild("\108\105\098")local i=require(Y:WaitForChild("\080\105\122\122\097\065\108\112\097\099\097"))local C=require(Y:WaitForChild("\080\114\111\109\105\115\101"))local R=require(Y:WaitForChild("\083\105\103\110\097\108"))local M=require(v:WaitForChild("\065\099\116\105\111\110\115"))local k=require(v:WaitForChild("\084\104\117\110\107\115"))local H=require(script:WaitForChild("\083\101\114\118\101\114\065\112\105"))local c=i.GameModule:extend("\083\101\114\118\101\114\065\112\105")function c.getApi(A)return C.async(function(v,Y)if not A.api then A.apiCreated:wait()end v(A.api)end)end function c.create(A)A.apiCreated=R.new()end function c.preInit(A)A.api=H.create({ready=function(v)(A.core:getModule("\080\108\097\121\101\114\072\097\110\100\108\101\114")):playerReady(v)end;requestCoinCollect=function(v,Y)(A.core:getModule("\067\111\105\110\115")):requestCoinCollect(v,Y)end,requestCandyCollect=function(v,Y)(A.core:getModule("\067\097\110\100\121")):requestCollect(v,Y)end,portalActivate=function(v,Y)A.store:dispatch(M.PORTAL_ACTIVATE(v,Y));(A.core:getModule("\080\111\114\116\097\108\115\076\105\115\116\101\110\101\114")):portalActivate(v,Y)end,buyAsset=function(v,Y)A.store:dispatch(k.ASSET_TRYBUY(v,Y))end;buyDevproduct=function(v,Y)(A.core:getModule("\067\097\115\104\105\101\114")):promptPurchase(v,Y)end;equipAsset=function(v,Y)A.store:dispatch(k.ASSET_TRYEQUIP(v,Y))end;unequipAsset=function(v,Y)A.store:dispatch(M.ASSET_UNEQUIP(v,Y))end;equippedAction=function(A,v,Y)print(("\037\115 \117\115\101\100 \037\115"):format(A.Name,v))end})A.apiCreated:fire(A.api)end function c.init(A)local v=A.core:getModule("\083\116\111\114\101\067\111\110\116\097\105\110\101\114");(v:getStore()):andThen(function(v)A.store=v A.api:connect()end)end function c.postInit(A) end return c
-- wrapper for lpghatguy's common api implementation
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local common = ReplicatedStorage:WaitForChild("common")
local lib = ReplicatedStorage:WaitForChild("lib")

local PizzaAlpaca = require(lib:WaitForChild("PizzaAlpaca"))
local Promise = require(lib:WaitForChild("Promise"))
local Signal = require(lib:WaitForChild("Signal"))

local Actions = require(common:WaitForChild("Actions"))
local Thunks = require(common:WaitForChild("Thunks"))

local ServerApi = require(script:WaitForChild("ServerApi"))

local ServerApiWrapper = PizzaAlpaca.GameModule:extend("ServerApi")

function ServerApiWrapper:getApi()
    return Promise.async(function(resolve, reject)
        if not self.api then self.apiCreated:wait() end
        resolve(self.api)
    end)
end

function ServerApiWrapper:create()
	self.apiCreated = Signal.new()
end

function ServerApiWrapper:preInit()
	self.api = ServerApi.create({
		ready = function(player)
			self.core:getModule("PlayerHandler"):playerReady(player)
		end,

		requestCoinCollect = function(player,coinSpawn)
			self.core:getModule("Coins"):requestCoinCollect(player,coinSpawn)
		end,

		requestCandyCollect = function(player,coinSpawn)
			self.core:getModule("Candy"):requestCollect(player,coinSpawn)
		end,

		portalActivate = function(player,portalName)
			self.store:dispatch(Actions.PORTAL_ACTIVATE(player,portalName))
			self.core:getModule("PortalsListener"):portalActivate(player,portalName)
		end,

		buyAsset = function(player,assetId)
			self.store:dispatch(Thunks.ASSET_TRYBUY(player, assetId))
		end,

		buyDevproduct = function(player,devproductId)
			self.core:getModule("Cashier"):promptPurchase(player,devproductId)
		end,

		equipAsset = function(player,assetId)
			self.store:dispatch(Thunks.ASSET_TRYEQUIP(player, assetId))
		end,

		unequipAsset = function(player,assetId)
			self.store:dispatch(Actions.ASSET_UNEQUIP(player, assetId))
		end,

		equippedAction = function(player, assetid, payload)
			print(("%s used %s"):format(player.Name,assetid))
		end,
	})

	self.apiCreated:fire(self.api)
end

function ServerApiWrapper:init()
    local storeContainer = self.core:getModule("StoreContainer")
	storeContainer:getStore():andThen(function(store)
		self.store = store
		self.api:connect()
	end)
end

function ServerApiWrapper:postInit()
end


return ServerApiWrapper