local A=require(script.Parent.RopostMethods)local i={}i.__index=i function i.new(A)local V=setmetatable({channel=A;unsubscribers={}},i)return V end function i.publish(M,i,V,j)return A.publish({channel=M.channel,topic=i;data=V,players=j})end function i.destroy(A)for A,i in pairs(A.unsubscribers)do i()end end function i.subscribe(j,i,V)local M=A.subscribe({channel=j.channel;topic=i;callback=V})table.insert(j.unsubscribers,M)return function()table.remove(j.unsubscribers,table.find(j.unsubscribers,M))M()end end return i
local RopostMethods = require(script.Parent.RopostMethods)

local ChannelDefinition = {}
ChannelDefinition.__index = ChannelDefinition

function ChannelDefinition.new(channel)
	local self = setmetatable({
		channel = channel,
		unsubscribers = {},
	}, ChannelDefinition)
	return self
end

function ChannelDefinition:publish(topic, data, players)
	return RopostMethods.publish({
		channel = self.channel,
		topic = topic,
		data = data,
		players = players,
	})
end

function ChannelDefinition:destroy()
	for _, unsubscriber in pairs(self.unsubscribers) do
		unsubscriber()
	end
end

function ChannelDefinition:subscribe(topic, callback)
	local unsubscribe = RopostMethods.subscribe({
		channel = self.channel,
		topic = topic,
		callback = callback,
	})
	table.insert(self.unsubscribers, unsubscribe)
	return function()
		table.remove(self.unsubscribers, table.find(self.unsubscribers, unsubscribe))
		unsubscribe()
	end
end

return ChannelDefinition
