local z=require(script.Parent.Parent.Shared.Util)local s=game:GetService("\080\108\097\121\101\114\115")local B={}local function o(z)if B[z]then return B[z]elseif s:FindFirstChild(z)then B[z]=s[z].UserId return s[z].UserId else local o,X=pcall(s.GetUserIdFromNameAsync,s,z)if not o then return nil end B[z]=X return X end end local X={DisplayName="\070\117\108\108 \080\108\097\121\101\114 \078\097\109\101",Prefixes="\035 \112\111\115\105\116\105\118\101\073\110\116\101\103\101\114",Transform=function(B)local o=z.MakeFuzzyFinder(s:GetPlayers())return B,o(B)end,ValidateOnce=function(z)return o(z)~=nil,"\078\111 \112\108\097\121\101\114 \119\105\116\104 \116\104\097\116 \110\097\109\101 \099\111\117\108\100 \098\101 \102\111\117\110\100\046"end,Autocomplete=function(s,B)return z.GetNames(B)end,Parse=function(z)return o(z)end,Default=function(z)return z.Name end,ArgumentOperatorAliases={me="\046";all="\042";others="\042\042",random="\063"}}return function(s)s:RegisterType("\112\108\097\121\101\114\073\100",X)s:RegisterType("\112\108\097\121\101\114\073\100\115",z.MakeListableType(X,{Prefixes="\035 \112\111\115\105\116\105\118\101\073\110\116\101\103\101\114\115"}))end
local Util = require(script.Parent.Parent.Shared.Util)
local Players = game:GetService("Players")

local nameCache = {}
local function getUserId(name)
	if nameCache[name] then
		return nameCache[name]
	elseif Players:FindFirstChild(name) then
		nameCache[name] = Players[name].UserId
		return Players[name].UserId
	else
		local ok, userid = pcall(Players.GetUserIdFromNameAsync, Players, name)

		if not ok then
			return nil
		end

		nameCache[name] = userid
		return userid
	end
end

local playerIdType = {
	DisplayName = "Full Player Name",
	Prefixes = "# positiveInteger",

	Transform = function(text)
		local findPlayer = Util.MakeFuzzyFinder(Players:GetPlayers())

		return text, findPlayer(text)
	end,

	ValidateOnce = function(text)
		return getUserId(text) ~= nil, "No player with that name could be found."
	end,

	Autocomplete = function(_, players)
		return Util.GetNames(players)
	end,

	Parse = function(text)
		return getUserId(text)
	end,

	Default = function(player)
		return player.Name
	end,

	ArgumentOperatorAliases = {
		me = ".",
		all = "*",
		others = "**",
		random = "?",
	},
}

return function(cmdr)
	cmdr:RegisterType("playerId", playerIdType)
	cmdr:RegisterType(
		"playerIds",
		Util.MakeListableType(playerIdType, {
			Prefixes = "# positiveIntegers",
		})
	)
end
