local M=require("\099\108\105\101\110\116\047\110\101\116\119\111\114\107")local D=require("\115\104\097\114\101\100\047\111\117\116\112\117\116\047\109\101\115\115\097\103\101\084\121\112\101\115")local K=require("\115\104\097\114\101\100\047\115\105\103\110\097\108")local W=require("\115\104\097\114\101\100\047\102\117\110\099\116\105\111\110\115")local f={}f.MessageType=D f.MessageOut=K.new()f.MessageIdDropped=K.new()function f.append(P,M,K,W)assert(M,"\078\111 \109\101\115\115\097\103\101\084\121\112\101 \103\105\118\101\110\046")assert(D[M],"\073\110\118\097\108\105\100 \109\101\115\115\097\103\101 \116\121\112\101\046")assert(K,"\078\111 \109\101\115\115\097\103\101 \103\105\118\101\110\046")f.MessageOut:Fire(nil,W or DateTime.now(),K,M)end function f.appendWithId(w,M,K,P,p)assert(M,"\078\111 \109\101\115\115\097\103\101\084\121\112\101 \103\105\118\101\110\046")assert(D[M],"\073\110\118\097\108\105\100 \109\101\115\115\097\103\101 \116\121\112\101\046")assert(K,"\078\111 \109\101\115\115\097\103\101 \103\105\118\101\110\046")p=p or W.randomString()f.MessageOut:Fire(p,P or DateTime.now(),K,M)return p end function f.edit(p,M,K,W,P)assert(M,"\078\111 \109\101\115\115\097\103\101 \105\100 \103\105\118\101\110\046")assert(K,"\078\111 \109\101\115\115\097\103\101\084\121\112\101 \103\105\118\101\110\046")assert(D[K],"\073\110\118\097\108\105\100 \109\101\115\115\097\103\101 \116\121\112\101\046")assert(W,"\078\111 \109\101\115\115\097\103\101 \103\105\118\101\110\046")f.MessageOut:Fire(M,P or DateTime.now(),W,K)end function f.dropId(D,M)assert(M,"\078\111 \109\101\115\115\097\103\101 \105\100 \103\105\118\101\110\046")f.MessageIdDropped:Fire(M)end M:RegisterEvent("\111\117\116\112\117\116\058\058\097\112\112\101\110\100",function(...)f:append(...)end)M:RegisterEvent("\111\117\116\112\117\116\058\058\097\112\112\101\110\100\087\105\116\104\073\100",function(...)f:appendWithId(...)end)M:RegisterEvent("\111\117\116\112\117\116\058\058\101\100\105\116",function(...)f:edit(...)end)M:RegisterEvent("\111\117\116\112\117\116\058\058\100\114\111\112\073\100",function(...)f:dropId(...)end)return f
local Network = require("client/network")
local MessageTypes = require("shared/output/messageTypes")
local Signal = require("shared/signal")
local Functions = require("shared/functions")

local Output = {}
Output.MessageType = MessageTypes
Output.MessageOut = Signal.new()
Output.MessageIdDropped = Signal.new()

function Output:append(messageType, message, dateTime)
	assert(messageType, "No messageType given.")
	assert(MessageTypes[messageType], "Invalid message type.")
	assert(message, "No message given.")

	Output.MessageOut:Fire(nil, dateTime or DateTime.now(), message, messageType)
end

function Output:appendWithId(messageType, message, dateTime, id)
	assert(messageType, "No messageType given.")
	assert(MessageTypes[messageType], "Invalid message type.")
	assert(message, "No message given.")

	id = id or Functions.randomString()
	Output.MessageOut:Fire(id, dateTime or DateTime.now(), message, messageType)

	return id
end

function Output:edit(id, messageType, message, dateTime)
	assert(id, "No message id given.")
	assert(messageType, "No messageType given.")
	assert(MessageTypes[messageType], "Invalid message type.")
	assert(message, "No message given.")

	Output.MessageOut:Fire(id, dateTime or DateTime.now(), message, messageType)
end

function Output:dropId(id)
	assert(id, "No message id given.")

	Output.MessageIdDropped:Fire(id)
end

Network:RegisterEvent("output::append", function(...)
	Output:append(...)
end)

Network:RegisterEvent("output::appendWithId", function(...)
	Output:appendWithId(...)
end)

Network:RegisterEvent("output::edit", function(...)
	Output:edit(...)
end)

Network:RegisterEvent("output::dropId", function(...)
	Output:dropId(...)
end)

return Output
