#ifndef REFS_H
#define REFS_H

#include "eis.h"
#include "echem.h"

#define REF_MODE_EIS  0
#define REF_MODE_LSV  1
#define REF_MODE_AMP  2
#define REF_MODE_CL   3
#define REF_MODE_PH   4

#define REF_EIS_RTIA_COUNT 8  /* RTIA 0-7 (skip ExtDe0) */

typedef struct {
    uint8_t low_idx;
    uint8_t high_idx;
    uint8_t valid;
} LpRtiaRange;

typedef struct {
    EISPoint pts[EIS_MAX_POINTS];
    uint32_t n_points;
    uint8_t valid;
} EisRefSlot;

typedef struct {
    EisRefSlot eis[REF_EIS_RTIA_COUNT];
    LpRtiaRange lsv_range;
    LpRtiaRange amp_range;
    LpRtiaRange cl_range;
    PhResult ph_ref;
    uint8_t ph_valid;
    uint8_t has_refs;
} RefStore;

void refs_collect(RefStore *store, const EISConfig *cfg);
void refs_send(const RefStore *store);
void refs_clear(RefStore *store);

#endif
