package ru.dbotthepony.mc.otm.network.syncher

import net.minecraft.network.RegistryFriendlyByteBuf
import ru.dbotthepony.kommons.util.Observer

/**
 * An object capable of synching its state to remotes
 */
interface ISynchable : Observer {
	fun read(stream: RegistryFriendlyByteBuf)

	/**
	 * Provided [listener] is to be considered thread-safe, and can be called at any time
	 *
	 * Created [IRemoteState] is implied to have [IRemoteState.invalidate] called implicitly internally upon creation
	 */
	fun createRemoteState(listener: Runnable): IRemoteState

	val shouldBeObserved: Boolean
		get() = false

	/**
	 * Whenever this synchable has remotes, optional operation and can safely always return false
	 */
	val hasRemotes: Boolean

	/**
	 * Whenever [read] has been called at least once
	 */
	val isRemote: Boolean

	override fun observe(): Boolean {
		// no op
		return false
	}
}
