#ifndef DEVICE_DATA_MODEL_H
#define DEVICE_DATA_MODEL_H

#include <stdint.h>
#include <stdbool.h>

#define MIN_SEND_INTERVAL_MS         1000
#define MAX_SEND_INTERVAL_MS         60000
#define MIN_ACQ_INTERVAL_MS          10

#define DEFAULT_SEND_INTERVAL_MS     1000
#define DEFAULT_ACQUISITION_INTERVAL_MS 1000

#define STORAGE_CHANGE_PCT           2
#define STORAGE_HEARTBEAT_S          60

#define SENSOR_OFF_VALUE             180

/* timestamp_s is uint16_t (~18.2h max); auto-stop kept below 65534s. */
#define AUTO_STOP_LIMIT_S            36000

#define ADC_SAMPLE_COUNT             200
#define ADC_READ_TIMEOUT_MS          50

#define NVS_MEASUREMENT_ID           0x01
#define NVS_CALIBRATION_ID           0x02
#define NVS_SESSION_META_ID          0x03
/* Written on every measurement_put so an unclean shutdown can recover
 * the live record_count of the active session at boot. */
#define NVS_ACTIVE_COUNT_ID          0x04

/* Wire-format session id: the flat refactor exposes a single session. */
#define FIXED_SESSION_ID             0x01

struct measurement_payload {
	uint16_t timestamp_s;
	uint16_t value;
} __attribute__((packed));

struct calibration_params {
	uint16_t raw_a;
	uint16_t real_c;
	uint16_t raw_b;
	uint16_t real_d;
	float    slope;
	float    offset;
	bool     is_valid;
};

enum app_mode {
	APP_MODE_IDLE   = 0x00,
	APP_MODE_NOTIFY = 0x01,
	APP_MODE_RECORD = 0x02,
};

struct active_session {
	uint16_t record_count;
	uint8_t  is_active;
} __attribute__((packed));

#endif /* DEVICE_DATA_MODEL_H */
