#pragma once
#include <cstdint>

extern uint64_t g_sleep_us;
extern bool     g_deep_sleep_started;
extern int      g_ext0_wakeup_pin;
extern int      g_ext0_wakeup_level;

// Mirror of the ESP-IDF wakeup-cause enum that the firmware actually checks.
// Tests set g_wakeup_cause directly to simulate cold-boot vs timer-wake.
typedef enum {
    ESP_SLEEP_WAKEUP_UNDEFINED = 0,    // cold boot / power-on / hard reset
    ESP_SLEEP_WAKEUP_EXT0      = 2,
    ESP_SLEEP_WAKEUP_EXT1      = 3,
    ESP_SLEEP_WAKEUP_TIMER     = 4,    // returned to userland after deep-sleep timer
    ESP_SLEEP_WAKEUP_TOUCHPAD  = 5,
    ESP_SLEEP_WAKEUP_ULP       = 6,
} esp_sleep_wakeup_cause_t;

extern esp_sleep_wakeup_cause_t g_wakeup_cause;

// gpio_num_t alias for the wakeup helper. The real header is part of
// esp-idf; for native tests we just use int.
typedef int gpio_num_t;
#ifndef GPIO_NUM_0
#define GPIO_NUM_0 0
#endif

inline void esp_sleep_enable_timer_wakeup(uint64_t us) { g_sleep_us = us; }
inline void esp_sleep_enable_ext0_wakeup(gpio_num_t pin, int level) {
    g_ext0_wakeup_pin   = pin;
    g_ext0_wakeup_level = level;
}
inline void esp_deep_sleep_start() { g_deep_sleep_started = true; }
inline esp_sleep_wakeup_cause_t esp_sleep_get_wakeup_cause() { return g_wakeup_cause; }
