#ifndef MVGAL_AI_FEATURES_H
#define MVGAL_AI_FEATURES_H

#include "mvgal/mvgal_ai.h"
#include "mvgal/mvgal_scheduler.h"
#include "mvgal/mvgal_types.h"
#include "scheduler_internal.h"

#ifdef __cplusplus
extern "C" {
#endif

/* ── Feature extraction ──────────────────────────────────────────────── */

/*
 * Extract AI features from the current scheduler state and a workload
 * descriptor. Fills `features` with normalized signals for the AI model.
 *
 * Returns 0 on success, -1 on error.
 */
int mvgal_ai_features_extract(const mvgal_scheduler_state_t *sched_state,
                               const mvgal_workload_descriptor_t *workload,
                               mvgal_ai_features_t *features);

/*
 * Run AI prediction on extracted features to select the optimal GPU.
 * Calls mvgal_ai_model_predict internally. Sets prediction->recommended_gpu
 * to the GPU index the model recommends.
 *
 * Returns 0 on success, -1 if model not loaded or prediction fails.
 */
int mvgal_ai_features_predict(const mvgal_ai_features_t *features,
                               mvgal_ai_prediction_t *prediction);

/*
 * Hardened dispatch: combines extract + predict + dispatch in one call.
 * Internally calls mvgal_scheduler_find_best_gpu if AI model is unavailable,
 * then delegates to the strategy dispatch.
 *
 * Returns the chosen GPU index, or -1 on failure.
 */
int mvgal_ai_features_dispatch(mvgal_scheduler_state_t *sched_state,
                                const mvgal_workload_descriptor_t *workload);

/* ── Lifecycle helpers ───────────────────────────────────────────────── */

/* Returns true if the AI model is loaded and ready for predictions */
bool mvgal_ai_features_ready(void);

/* Reload the AI model (calls mvgal_ai_model_load internally).
 * Returns the new model handle (possibly NULL on failure). */
mvgal_ai_model_t mvgal_ai_features_reload_model(const char *model_path);

#ifdef __cplusplus
}
#endif

#endif /* MVGAL_AI_FEATURES_H */
