package dev.adriankuta.visualizer

/**
 * A utility class for calculating moving averages over a sliding window.
 * Follows the Single Responsibility Principle by focusing solely on moving average calculations.
 */
class MovingAverage(private val windowSize: Int) {
    private val values = mutableListOf<Double>()

    /**
     * Processes a new value and returns the current moving average.
     * 
     * @param newValue The new value to add to the moving average calculation
     * @return The current moving average
     */
    fun process(newValue: Double): Double {
        values.add(newValue)

        // Remove oldest value if window size exceeded
        if (values.size > windowSize) {
            values.removeAt(0)
        }

        return values.average()
    }

    /**
     * Resets the moving average calculation.
     */
    fun reset() {
        values.clear()
    }

    /**
     * Returns the current number of values in the window.
     */
    val currentSize: Int
        get() = values.size
}
