local z=require(script.Parent.Parent.Shared.Util)local s={"\094\037\097\091\037\119\095\093\042\036","\094\037\036\037\097\091\037\119\095\093\042\036","\094\037\046\037\097\091\037\119\095\093\042\036","\094\037\036\037\046\037\097\091\037\119\095\093\042\036"}return function(B)local o={Autocomplete=function(z)local s=B.Cmdr.Util.MakeFuzzyFinder(B.Cmdr.Util.DictionaryKeys(B:GetStore("\118\097\114\115\095\117\115\101\100")or{}))return s(z)end,Validate=function(z)for s,B in ipairs(s)do if z:match(B)then return true end end return false,"\075\101\121 \110\097\109\101\115 \109\117\115\116 \115\116\097\114\116 \119\105\116\104 \097\110 \111\112\116\105\111\110\097\108 \109\111\100\105\102\105\101\114\058 \046 \036 \111\114 \036\046 \097\110\100 \109\117\115\116 \098\101\103\105\110 \119\105\116\104 \097 \108\101\116\116\101\114\046"end,Parse=function(z)return z end}B:RegisterType("\115\116\111\114\101\100\075\101\121",o)B:RegisterType("\115\116\111\114\101\100\075\101\121\115",z.MakeListableType(o))end
local Util = require(script.Parent.Parent.Shared.Util)

local VALID_STORED_KEY_NAME_PATTERNS = {
	"^%a[%w_]*$",
	"^%$%a[%w_]*$",
	"^%.%a[%w_]*$",
	"^%$%.%a[%w_]*$",
}

return function(registry)
	local storedKeyType = {
		Autocomplete = function(text)
			local find = registry.Cmdr.Util.MakeFuzzyFinder(
				registry.Cmdr.Util.DictionaryKeys(registry:GetStore("vars_used") or {})
			)

			return find(text)
		end,

		Validate = function(text)
			for _, pattern in ipairs(VALID_STORED_KEY_NAME_PATTERNS) do
				if text:match(pattern) then
					return true
				end
			end

			return false, "Key names must start with an optional modifier: . $ or $. and must begin with a letter."
		end,

		Parse = function(text)
			return text
		end,
	}
	registry:RegisterType("storedKey", storedKeyType)
	registry:RegisterType("storedKeys", Util.MakeListableType(storedKeyType))
end
