local m=require(script.Parent.Parent.TrueSignal)local q=require(script.Parent.prepArgs)local x={}x.__index=x function x._new(q,L,E)local A=setmetatable({},x)A.name=q A._server=L A._client=E A.OnClientEvent=m.new(false,true)A._client._remoteEvents[q]=A return A end function x._fireClient(m,...)m.OnClientEvent:fire(...)end function x._destroy(m)m._client._remoteEvents[m.name]=nil m.OnClientEvent:destroy()end function x.fireServer(m,...)local x={q(...)}if m._server._remoteEvents[m.name]then(m._server:getRemoteEvent(m.name)):_fireServer(m._client,table.unpack(x))end end x.FireServer=x.fireServer return x
local TrueSignal = require(script.Parent.Parent.TrueSignal)

local prepArgs = require(script.Parent.prepArgs)

--[=[
    RemoteEventClient class

    @class RemoteEventClient
]=]
local RemoteEventClient = {}
RemoteEventClient.__index = RemoteEventClient

--[=[
    Constructs a new RemoteEventClient object

    @param name string
    @param server Server
    @param client Client
    @return RemoteEventClient

    @private
]=]
function RemoteEventClient._new(name, server, client)
    local self = setmetatable({}, RemoteEventClient)

    self.name = name

    self._server = server
    self._client = client

    self.OnClientEvent = TrueSignal.new(false, true)

    self._client._remoteEvents[name] = self

    return self
end

--[=[
    Called by RemoteEventServer to fire the client

    @param ... any
    
    @private
]=]
function RemoteEventClient:_fireClient(...)
    self.OnClientEvent:fire(...)
end

--[=[
    Called by RemoteEventServer to clean up
    
    @private
]=]
function RemoteEventClient:_destroy()
    self._client._remoteEvents[self.name] = nil
    self.OnClientEvent:destroy()
end

--[=[
    Fires the corresponding RemoteEventServer instance's OnServerEvent signal with the passed args

    @param ... any
]=]
function RemoteEventClient:fireServer(...)
    local args = {prepArgs(...)}

    if self._server._remoteEvents[self.name] then
        self._server:getRemoteEvent(self.name):_fireServer(self._client, table.unpack(args))
    end
end

--[=[
    PascalCase alias for fireServer

    @param ... any

    @method FireServer
    @within RemoteEventClient
]=]
RemoteEventClient.FireServer = RemoteEventClient.fireServer

return RemoteEventClient