local i=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local M=i:WaitForChild("\099\111\109\109\111\110")local D=i:WaitForChild("\108\105\098")local p=require(D:WaitForChild("\080\105\122\122\097\065\108\112\097\099\097"))local x=require(D:WaitForChild("\083\105\103\110\097\108"))local K=require(D:WaitForChild("\080\114\111\109\105\115\101"))local o=require(script:WaitForChild("\067\108\105\101\110\116\065\112\105"))local j=p.GameModule:extend("\067\108\105\101\110\116\065\112\105")function j.getApi(i)return K.async(function(M,D)if not i.api then i.apiCreated:wait()end M(i.api)end)end function j.create(i)i.apiCreated=x.new()end function j.preInit(i) end function j.init(i)local M=i.core:getModule("\083\116\111\114\101\067\111\110\116\097\105\110\101\114")local D=i.core:getModule("\067\111\105\110\083\112\097\119\110\101\114")local p=i.core:getModule("\067\097\110\100\121\083\112\097\119\110\101\114")i.api=o.new({initialPlayerState=function(i)M:createStore(i)end;storeAction=function(i)(M:getStore()):andThen(function(M)M:dispatch(i)end)end;coinRespawn=function(i)D:spawnCoin(i)end;candyRespawn=function(i)p:spawn(i)end,equippedBroadcast=function(i,M,D) end})i.apiCreated:fire(i.api)end function j.postInit(i)i.api:connect()i.api:ready()end return j
-- 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 Signal = require(lib:WaitForChild("Signal"))
local Promise = require(lib:WaitForChild("Promise"))
local ClientApi = require(script:WaitForChild("ClientApi"))

local ClientApiWrapper = PizzaAlpaca.GameModule:extend("ClientApi")

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

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

function ClientApiWrapper:preInit()
end

function ClientApiWrapper:init()
    local storeContainer = self.core:getModule("StoreContainer")
    local coinSpawner = self.core:getModule("CoinSpawner")
    local candySpawner = self.core:getModule("CandySpawner")
    self.api = ClientApi.new({
        initialPlayerState = function(gameState)
            storeContainer:createStore(gameState)
        end,

        storeAction = function(action)
            storeContainer:getStore():andThen(function(store)
                store:dispatch(action)
            end)
        end,

        coinRespawn = function(coinSpawn)
            coinSpawner:spawnCoin(coinSpawn)
        end,

        candyRespawn = function(spawner)
            candySpawner:spawn(spawner)
        end,

        equippedBroadcast = function(player, assetid, payload)
            -- TODO: Equipment use handling
        end,
    })

    self.apiCreated:fire(self.api)
end

function ClientApiWrapper:postInit()
    self.api:connect()
    self.api:ready()
end


return ClientApiWrapper