local C=require(script.Parent.Parent.Shared.Util)local O=game:GetService("\080\108\097\121\101\114\115")local V={}local function L(C)if V[C]then return V[C]elseif O:FindFirstChild(C)then V[C]=O[C].UserId return O[C].UserId else local L,j=pcall(O.GetUserIdFromNameAsync,O,C)if not L then return nil end V[C]=j return j end end local j={DisplayName="\070\117\108\108 \080\108\097\121\101\114 \078\097\109\101";Prefixes="\035 \105\110\116\101\103\101\114";Transform=function(V)local L=C.MakeFuzzyFinder(O:GetPlayers())return V,L(V)end;ValidateOnce=function(C)return L(C)~=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(O,V)return C.GetNames(V)end;Parse=function(C)return L(C)end,Default=function(C)return C.Name end,ArgumentOperatorAliases={me="\046",all="\042",others="\042\042",random="\063"}}return function(O)O:RegisterType("\112\108\097\121\101\114\073\100",j)O:RegisterType("\112\108\097\121\101\114\073\100\115",C.MakeListableType(j,{Prefixes="\035 \105\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 = "# integer";

	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 = "# integers"
	}))
end
