#pragma once

#include <cstddef>
#include <cstdint>

#ifdef XYPARSER_EXPORTS
#define XYPARSER_API __declspec(dllexport)
#else
#define XYPARSER_API __declspec(dllimport)
#endif

extern "C" {

typedef void* XYParserHandle;

enum {
    XYPARSER_MAX_CHANNELS = 64,
    XYPARSER_SAMPLES_PER_FRAME = 5
};

struct XYParserFrameSummary {
    std::uint32_t frame_index;
    std::uint8_t channel_count;
    std::uint8_t battery;
    std::uint8_t sample_count;
    double channel_values_uv[XYPARSER_SAMPLES_PER_FRAME][XYPARSER_MAX_CHANNELS];
    std::uint8_t trigger_types[XYPARSER_SAMPLES_PER_FRAME];
    std::uint8_t trigger_indices[XYPARSER_SAMPLES_PER_FRAME];
};

XYPARSER_API XYParserHandle XYParser_CreateParser(std::uint8_t channel_count);
XYPARSER_API void XYParser_DestroyParser(XYParserHandle handle);
XYPARSER_API void XYParser_SetAdcParams(XYParserHandle handle, double vref, double gain);
XYPARSER_API void XYParser_SetBypassChecksum(XYParserHandle handle, int bypass);
XYPARSER_API int XYParser_Feed(XYParserHandle handle,
                               const std::uint8_t* data,
                               std::size_t size,
                               XYParserFrameSummary* out_summaries,
                               int max_summaries);
XYPARSER_API const char* XYParser_GetLastError(XYParserHandle handle);

}
