local U=import("\046\047\116\121\112\101\075\101\121")local function N(N,P,F)local s=newproxy(true)local o={Value=F,Name=P,EnumType=N};(getmetatable(s))[U]="\069\110\117\109\073\116\101\109";(getmetatable(s)).__tostring=function()return("\069\110\117\109\046\037\115\046\037\115"):format(tostring(N),P)end;(getmetatable(s)).__index=function(U,N)local P=o[N]if P==nil then error(("\037\115 \105\115 \110\111\116 \097 \118\097\108\105\100 \109\101\109\098\101\114"):format(tostring(N)),2)end return P end return s end local function P(P,F)local s=newproxy(true)local o={}for U,P in pairs(F)do o[U]=N(s,U,P)end;(getmetatable(s))[U]="\069\110\117\109";(getmetatable(s)).__tostring=function()return P end;(getmetatable(s)).__index=function(U,N)local P=o[N]if P==nil then error(("\037\115 \105\115 \110\111\116 \097 \118\097\108\105\100 \069\110\117\109\073\116\101\109"):format(tostring(N)),2)end return P end return s end return P
local typeKey = import("./typeKey")

local function createEnumVariant(enum, variantName, variantValue)
	local enumVariant = newproxy(true)

	local internal = {
		Value = variantValue,
		Name = variantName,
		EnumType = enum,
	}

	getmetatable(enumVariant)[typeKey] = "EnumItem"

	getmetatable(enumVariant).__tostring = function()
		return ("Enum.%s.%s"):format(tostring(enum), variantName)
	end

	getmetatable(enumVariant).__index = function(self, key)
		local value = internal[key]

		if value == nil then
			error(("%s is not a valid member"):format(tostring(key)), 2)
		end

		return value
	end

	return enumVariant
end

local function createEnum(enumName, variantValues)
	local enum = newproxy(true)

	local variants = {}

	for variantName, value in pairs(variantValues) do
		variants[variantName] = createEnumVariant(enum, variantName, value)
	end

	getmetatable(enum)[typeKey] = "Enum"

	getmetatable(enum).__tostring = function()
		return enumName
	end

	getmetatable(enum).__index = function(self, key)
		local variant = variants[key]

		if variant == nil then
			error(("%s is not a valid EnumItem"):format(tostring(key)), 2)
		end

		return variant
	end

	return enum
end

return createEnum