#pragma once
#include <cstddef>

struct TimeSeriesBuffer {
    float* data;
    size_t capacity;
    size_t count;
    size_t offset; // write head

    TimeSeriesBuffer(size_t cap);
    ~TimeSeriesBuffer();

    // Non-copyable, moveable
    TimeSeriesBuffer(const TimeSeriesBuffer&) = delete;
    TimeSeriesBuffer& operator=(const TimeSeriesBuffer&) = delete;
    TimeSeriesBuffer(TimeSeriesBuffer&& other) noexcept;
    TimeSeriesBuffer& operator=(TimeSeriesBuffer&& other) noexcept;

    void push(float value);
    float get(size_t index) const; // 0 = oldest
    float latest() const;
    float min() const;
    float max() const;
    float average() const;
    size_t size() const;
    bool full() const;

    // For ImPlot: copies data in order to a contiguous array
    // Returns actual count written
    size_t copy_ordered(float* out, size_t out_capacity) const;
};
