package ru.dbotthepony.mc.otm.data.codec

import com.mojang.serialization.DataResult
import com.mojang.serialization.DynamicOps
import com.mojang.serialization.MapCodec
import com.mojang.serialization.MapLike
import com.mojang.serialization.RecordBuilder
import java.util.stream.Stream

class SingletonCodec<V : Any>(val value: V) : MapCodec<V>() {
	override fun <T : Any?> keys(ops: DynamicOps<T>): Stream<T> {
		return Stream.empty()
	}

	override fun <T : Any?> decode(ops: DynamicOps<T>, input: MapLike<T>): DataResult<V> {
		return DataResult.success(value)
	}

	override fun <T : Any?> encode(input: V, ops: DynamicOps<T>, prefix: RecordBuilder<T>): RecordBuilder<T> {
		return prefix
	}
}
