package ru.dbotthepony.mc.otm.network.synchronizer

data class SetChangeset<out V>(
	val action: ChangesetAction,
	val value: V?
) {
	inline fun map(add: (V) -> Unit, remove: (V) -> Unit) {
		when (action) {
			ChangesetAction.ADD -> add.invoke(value!!)
			ChangesetAction.REMOVE -> remove.invoke(value!!)
			else -> {}
		}
	}

	inline fun map(add: (V) -> Unit, remove: (V) -> Unit, clear: () -> Unit) {
		when (action) {
			ChangesetAction.CLEAR -> clear.invoke()
			ChangesetAction.ADD -> add.invoke(value!!)
			ChangesetAction.REMOVE -> remove.invoke(value!!)
		}
	}
}
