local y=require(script.Parent.Parent.Promise)local W=require(script.Parent._config)local e=game:GetService("\072\116\116\112\083\101\114\118\105\099\101")local T={}function T.call(T,z)return y.new(function(y,R)local c=W:withBaseUrl(string.format("\047\102\117\110\099\116\105\111\110\115\047\037\115",T))local S=0 for y,W in pairs(z)do S+=1 local T=S==1 and"\063"or"\038"if typeof(W)=="\116\097\098\108\101"then local z=e:JSONEncode(W)c..=string.format("\037\115\037\115\061\037\115",T,y,e:UrlEncode(z))else c..=string.format("\037\115\037\115\061\037\115",T,y,e:UrlEncode(W))end end local H=e:RequestAsync({Url=c;Method="\080\079\083\084",Headers=W:getHeaders()})if H.Success then y((e:JSONDecode(H.Body)).result)return end R(e:JSONDecode(H.Body))end)end return T
local Promise = require(script.Parent.Parent.Promise)
local _config = require(script.Parent._config)
local HttpService = game:GetService("HttpService")

local Functions = {}

function Functions.call(functionName, params)
    return Promise.new(function(resolve, reject)
        local url = _config:withBaseUrl(string.format("/functions/%s", functionName))

        local fieldNumber = 0
        for k, v in pairs(params) do
            fieldNumber += 1
            local delimiter = (fieldNumber == 1) and "?" or "&"
            
            if typeof(v) == "table" then
                local serialized = HttpService:JSONEncode(v)
                url ..= string.format("%s%s=%s", delimiter, k, HttpService:UrlEncode(serialized))
            else
                url ..= string.format("%s%s=%s", delimiter, k, HttpService:UrlEncode(v))
            end
        end

        local response = HttpService:RequestAsync({
            Url = url,
            Method = "POST",
            Headers = _config:getHeaders()
        })

        if response.Success then
            resolve(HttpService:JSONDecode(response.Body).result)
            return
        end

        reject(HttpService:JSONDecode(response.Body))
    end)
end

return Functions
