local o=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local T=o:WaitForChild("\099\111\109\109\111\110")local m=require(T:WaitForChild("\083\101\108\101\099\116\111\114\115"))local function M(o,T,M)local N=o.store:getState()local y=m.getTotalCoinsCollected(N,T)or 0 return y>M end return function(o,T)return{id="\067\111\105\110\115\095"..o,name=o.." \067\111\105\110\115";desc="\079\098\116\097\105\110 "..(o.." \099\111\105\110\115\046"),badgeId=T,startListening=function(T,m)local N=T:getModule("\067\111\105\110\115")N.coinCollected:connect(function(N)if M(T,N,o)then m(N)end end)end;queryComplete=function(T,m)return M(T,m,o)end}end
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local common = ReplicatedStorage:WaitForChild("common")

local Selectors = require(common:WaitForChild("Selectors"))

-- function that returns true if a player has completed this objective
local function queryComplete(server,player,quantity)
    local state = server.store:getState()
    local totalCoinsCollected = Selectors.getTotalCoinsCollected(state,player) or 0

    return totalCoinsCollected > quantity
end

return function(quantity,badgeId)
    return {
        id = "Coins_"..quantity,
        name = quantity.." Coins",
        desc = "Obtain "..quantity.." coins.",
        badgeId = badgeId,
        startListening = (function(server, awardBadge)
            local coins = server:getModule("Coins")

            coins.coinCollected:connect(function(player)
                if queryComplete(server, player, quantity) then
                    awardBadge(player)
                end
            end)
        end),
        queryComplete = (function(server,player) return queryComplete(server,player,quantity) end),
    }
end