#pragma once

#include "XYParserApi.h"

#include <array>
#include <cstdint>
#include <deque>

class XYImpedanceProcessor {
public:
    explicit XYImpedanceProcessor(std::uint8_t channel_count = 0);

    void SetChannelCount(std::uint8_t channel_count);
    void SetSampleRate(int sample_rate);
    void SetEnabled(bool enabled);
    void Reset();

    void PushFrame(const XYParserFrameSummary& frame);
    int Read(XYParserImpedanceSummary* out_summaries, int max_summaries);

private:
    using Sample = std::array<double, XYPARSER_MAX_CHANNELS>;

    void ProcessPendingWindows();
    XYParserImpedanceSummary BuildSummaryFromWindow() const;
    std::uint16_t EstimateImpedanceValue(std::size_t channel_index) const;

private:
    std::uint8_t channel_count_ = 0;
    int sample_rate_ = 250;
    bool enabled_ = false;
    std::deque<Sample> cached_samples_;
    std::deque<XYParserImpedanceSummary> pending_results_;
};
