package ru.dbotthepony.mc.otm.core.chart

import com.mojang.serialization.Codec
import net.minecraft.network.RegistryFriendlyByteBuf
import ru.dbotthepony.mc.otm.core.collect.reduce
import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.data.codec.DecimalCodec
import ru.dbotthepony.mc.otm.network.MatteryStreamCodec

class DecimalHistoryChart : AbstractHistoryChart<Decimal> {
	constructor(resolution: Int, width: Int) : super(resolution, width)
	constructor(ticks: Int) : this(1, ticks)

	override fun calculateAverage(input: List<Decimal>): Decimal {
		return input.iterator().reduce(Decimal.ZERO, Decimal::plus) / Decimal(input.size)
	}

	override fun sum(input: List<Decimal>): Decimal {
		return input.iterator().reduce(Decimal.ZERO, Decimal::plus)
	}

	override fun sum(a: Decimal, b: Decimal): Decimal {
		return a + b
	}

	override fun identity(): Decimal {
		return Decimal.ZERO
	}

	override val codec: Codec<Decimal>
		get() = DecimalCodec
	override val streamCodec: MatteryStreamCodec<RegistryFriendlyByteBuf, Decimal>
		get() = DecimalCodec.NETWORK
}
