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

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

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