#pragma once
// Network-facing interface the board layer may call.
//
// The board owns the Settings > Network UI and the provisioning screen, but it
// must not depend on the app component's headers or on ESP-IDF Wi-Fi. `main`
// implements these functions on top of wifi_manager / WiFiProfileStore. This
// keeps credential persistence and station policy out of board.cpp while still
// letting the UI query counts and start an explicit provisioning session.
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

#include "esp_err.h"
#include "wifi_selection.h"

#ifdef __cplusplus
extern "C" {
#endif

// Link / profile status for the Network screens. Only SSIDs cross this boundary;
// no password is ever returned.
typedef enum {
    BOARD_WIFI_OFFLINE = 0,
    BOARD_WIFI_CONNECTING,
    BOARD_WIFI_CONNECTED,
    BOARD_WIFI_NO_KNOWN,
} board_wifi_state_t;

board_wifi_state_t board_network_state(void);
// Human label for the current link state ("CONNECTED", "OFFLINE", ...).
const char *board_network_state_label(void);
const char *board_network_current_ssid(void);
size_t board_network_profile_count(void);
const char *board_network_profile_ssid(size_t index);

// Forget one known network by SSID, or every network.
esp_err_t board_network_forget(const char *ssid);
esp_err_t board_network_forget_all(void);

// ---- Explicit provisioning -------------------------------------------------
// Start/stop the manual SoftAP provisioning mode. `board_network_start_setup`
// refuses when an approval is pending and returns ESP_ERR_INVALID_STATE.
esp_err_t board_network_start_setup(void);
void board_network_stop_setup(void);
bool board_network_setup_running(void);
bool board_network_setup_blocked(void);
// True while a candidate credential test owns the station interface (Portal or
// USB). The Human Gate checks this so it can preempt an in-flight candidate.
bool board_network_candidate_active(void);
// Human Gate preemption: cancel any in-flight candidate and stop the SoftAP
// provisioning session so the Approval owns both the screen and the buttons.
void board_network_preempt_for_approval(void);

// Provisioning screen values. The password is the fixed provisioning constant,
// not a device credential.
const char *board_network_setup_ssid(void);
const char *board_network_setup_password(void);
const char *board_network_setup_address(void);
// Candidate outcome label for the provisioning status line.
const char *board_network_setup_status(void);

#ifdef __cplusplus
}
#endif