#pragma once

#include <cstddef>
#include <utility>
#include <vector>

/**
 * Min/max envelope decimator for oscilloscope-style rendering.
 *
 * For N samples mapped to W pixel columns, computes min and max in each
 * column.  ImPlot::PlotShaded renders the envelope as a filled band.
 * When W >= N (1:1 or better) the input is returned unchanged.
 */
class Decimator {
public:
    struct Envelope {
        std::vector<double> t;
        std::vector<double> vmin;
        std::vector<double> vmax;
    };

    /** float* input (legacy, kept for overview buffer). */
    static Envelope decimate(const float* t_raw, const float* v_raw,
                             size_t N, int cols,
                             double t_min, double t_max);

    /** double* input (used for SignalBuffer data). */
    static Envelope decimate(const double* t_raw, const double* v_raw,
                             size_t N, int cols,
                             double t_min, double t_max);
};

/** Quick boxcar overview downsampling. */
std::vector<std::pair<double,double>>
overview_downsample(const double* t, const double* v, size_t N, size_t target);
