local R=require(script.Parent.MockMemoryStoreQuota)local J=require(script.Parent.MockMemoryStoreUtils)local W={}W.__index=W function W.new(R)return setmetatable({mapValues={}},W)end function W.GetAsync(Q,W)J.AssertKeyIsValid(W)R:ProcessReadRequest()local V=Q.mapValues[W]if V then return V.innerValue else return nil end end function W.SetAsync(s,W,Q,V)J.AssertKeyIsValid(W)assert(V,"\069\120\112\105\114\097\116\105\111\110 \114\101\113\117\105\114\101\100")assert(V<=J.MAX_EXPIRATION_SECONDS,"\069\120\099\101\101\100\115 \109\097\120 \101\120\112\105\114\097\116\105\111\110 \116\105\109\101")local n={innerValue=Q;expiration=tick()+V}R:ProcessWriteRequest()local q=s.mapValues[W]~=nil s.mapValues[W]=n return q end function W.UpdateAsync(Q,R,J,W)assert(typeof(R)=="\115\116\114\105\110\103","\069\120\112\101\099\116\115 \107\101\121 \040\097\114\103\117\109\101\110\116 \035\049\041")assert(typeof(J)=="\102\117\110\099\116\105\111\110","\069\120\112\101\099\116\115 \116\114\097\110\115\102\111\114\109\070\117\110\099\116\105\111\110 \040\097\114\103\117\109\101\110\116 \035\050\041")assert(typeof(W)=="\110\117\109\098\101\114","\069\120\112\101\099\116\115 \101\120\112\105\114\097\116\105\111\110 \040\097\114\103\117\109\101\110\116 \035\051\041")local V=Q:GetAsync(R)local s=J(V)if s~=nil then Q:SetAsync(R,s,W)return s else return nil end end function W.RemoveAsync(W,J)R:ProcessWriteRequest()W.mapValues[J]=nil end function W.RemoveExpiringKey(J,R)J.mapValues[R]=nil end function W.GetRangeAsync(V,R,J,W,Q)error("\078\111\116 \121\101\116 \105\109\112\108\101\109\101\110\116\101\100",2)end return W
local MockMemoryStoreQuota = require(script.Parent.MockMemoryStoreQuota)
local MockMemoryStoreUtils = require(script.Parent.MockMemoryStoreUtils)

local MockMemoryStoreSortedMap = {}
MockMemoryStoreSortedMap.__index = MockMemoryStoreSortedMap;

function MockMemoryStoreSortedMap.new(name)
    return setmetatable({
        mapValues = {},
    }, MockMemoryStoreSortedMap)
end

function MockMemoryStoreSortedMap:GetAsync(key)
    MockMemoryStoreUtils.AssertKeyIsValid(key)
    MockMemoryStoreQuota:ProcessReadRequest()

    local value = self.mapValues[key]
    if value then
        return value.innerValue
    else
        return nil
    end
end

function MockMemoryStoreSortedMap:SetAsync(key, value, expiration)
    MockMemoryStoreUtils.AssertKeyIsValid(key)
    assert(expiration, "Expiration required")

    assert(expiration <= MockMemoryStoreUtils.MAX_EXPIRATION_SECONDS, "Exceeds max expiration time")

    local mapValue = {
        innerValue = value,
        expiration = tick() + expiration
    }

    MockMemoryStoreQuota:ProcessWriteRequest()
    local isExistingItem = self.mapValues[key] ~= nil
    self.mapValues[key] = mapValue

    return isExistingItem
end

function MockMemoryStoreSortedMap:UpdateAsync(key, transformFunction, expiration)
    assert(typeof(key) == "string", "Expects key (argument #1)")
    assert(typeof(transformFunction) == "function", "Expects transformFunction (argument #2)")
    assert(typeof(expiration) == "number", "Expects expiration (argument #3)")

    local oldValue = self:GetAsync(key)

    local newValue = transformFunction(oldValue)
    if newValue ~= nil then
        self:SetAsync(key, newValue, expiration)
        return newValue
    else
        return nil
    end
end

function MockMemoryStoreSortedMap:RemoveAsync(key)
    MockMemoryStoreQuota:ProcessWriteRequest()

    self.mapValues[key] = nil
end

function MockMemoryStoreSortedMap:RemoveExpiringKey(key)
    self.mapValues[key] = nil
end

function MockMemoryStoreSortedMap:GetRangeAsync(direction, count, exclusiveLowerBound, exclusiveUpperBound)
    error("Not yet implemented", 2)
end

return MockMemoryStoreSortedMap