#ifndef KIRAN_ENSEMBLE_V070_H
#define KIRAN_ENSEMBLE_V070_H

#include <stdint.h>

#define KIRAN_N_BASE_FEATURES   106
#define KIRAN_N_MEDIUM_ROLLING   14
#define KIRAN_N_LONG_ROLLING     20
#define KIRAN_N_MEDIUM_FEATURES (KIRAN_N_BASE_FEATURES + KIRAN_N_MEDIUM_ROLLING)
#define KIRAN_N_LONG_FEATURES   (KIRAN_N_BASE_FEATURES + KIRAN_N_LONG_ROLLING)

#define KIRAN_MEDIUM_LOOKBACK     4
#define KIRAN_LONG_LOOKBACK      20

#define KIRAN_WEIGHT_SHORT   1
#define KIRAN_WEIGHT_MEDIUM  2
#define KIRAN_WEIGHT_LONG    1
#define KIRAN_WEIGHT_SUM     4
#define KIRAN_THRESHOLD      0.7f

#define KIRAN_IDX_HR    0
#define KIRAN_IDX_TEMP 31
#define KIRAN_IDX_EDA  44
#define KIRAN_IDX_ACC  56

typedef struct {
    float hr[KIRAN_LONG_LOOKBACK];
    float eda[KIRAN_LONG_LOOKBACK];
    float acc[KIRAN_LONG_LOOKBACK];
    float temp[KIRAN_LONG_LOOKBACK];
    int count;
    int pos;
} KiranRollingBuffer;

typedef struct {
    float p_short;
    float p_medium;
    float p_long;
    float p_ensemble;
    int prediction;
} KiranResult;

void kiran_rolling_buffer_init(KiranRollingBuffer *buf);
void kiran_rolling_buffer_push(KiranRollingBuffer *buf, const float *base_features);

void kiran_compute_medium_rolling(const KiranRollingBuffer *buf, float *out14);
void kiran_compute_long_rolling(const KiranRollingBuffer *buf, float *out20);

float kiran_scaler_transform_predict(
    const float *features,
    int n_features,
    const float *scaler_mean,
    const float *scaler_scale,
    const int16_t *tree_left,
    const int16_t *tree_right,
    const int16_t *tree_split_idx,
    const float *tree_split_val,
    const float *tree_leaf_val,
    const int *tree_offsets,
    int n_trees,
    float base_score
);

KiranResult kiran_ensemble_predict(
    const float *base_features,
    KiranRollingBuffer *buf
);

float kiran_sigmoid(float x);

#endif
