#ifndef EVSE_LIMITS_H
#define EVSE_LIMITS_H

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

#ifdef __cplusplus
extern "C" {
#endif

// ============================
// Limit Status & Evaluation
// ============================

/**
 * @brief Sets the internal 'limit reached' flag.
 * Called internally when a limit condition is triggered.
 */
void evse_set_limit_reached(bool value);

/**
 * @brief Returns true if any runtime charging limit has been reached.
 */
bool evse_get_limit_reached(void);

/**
 * @brief Checks if any session limit has been exceeded (energy, time or power).
 * Should be called periodically during charging.
 */
void evse_limits_check(void);

// ============================
// Runtime Limit Configuration
// ============================

/**
 * @brief Get/set energy consumption limit (in Wh).
 */
uint32_t evse_get_consumption_limit(void);
void     evse_set_consumption_limit(uint32_t value);

/**
 * @brief Get/set maximum charging time (in seconds).
 */
uint32_t evse_get_charging_time_limit(void);
void     evse_set_charging_time_limit(uint32_t value);

/**
 * @brief Get/set minimum acceptable power level (in Watts).
 * If the power remains below this for a long time, the session may be interrupted.
 */
uint16_t evse_get_under_power_limit(void);
void     evse_set_under_power_limit(uint16_t value);

// ============================
// Default (Persistent) Limits
// ============================

/**
 * @brief Default values used after system boot or reset.
 * These can be restored from NVS or fallback values.
 */
uint32_t evse_get_default_consumption_limit(void);
void     evse_set_default_consumption_limit(uint32_t value);

uint32_t evse_get_default_charging_time_limit(void);
void     evse_set_default_charging_time_limit(uint32_t value);

uint16_t evse_get_default_under_power_limit(void);
void     evse_set_default_under_power_limit(uint16_t value);

#ifdef __cplusplus
}
#endif

#endif // EVSE_LIMITS_H
