// scenario_server.h — start the BOX-3 minimal HTTP server that accepts
// POST /game/scenario (Runtime 3 IR hot-load via reboot).
#pragma once

#include <stddef.h>

#include "esp_err.h"
#include "esp_http_server.h"

#ifdef __cplusplus
extern "C" {
#endif

esp_err_t scenario_server_start(void);

// Handle of the running server (NULL before scenario_server_start succeeds).
// Lets other modules (plip_virtual) register their URIs on the same port 80.
httpd_handle_t scenario_server_handle(void);

// Shared internal apply path (the spec's `_scenario_apply`): validate a
// Runtime 3 IR blob, atomically write it to SPIFFS, and schedule the hot-reload
// reboot. Used both by the HTTP POST /game/scenario handler and by the ESP-NOW
// receiver (scenario_mesh). `data` need not be NUL-terminated beyond `len`.
// Returns ESP_OK on success; ESP_ERR_INVALID_ARG / _INVALID_SIZE on bad input,
// ESP_FAIL on storage errors.
esp_err_t scenario_apply_buffer(const char *data, size_t len);

#ifdef __cplusplus
}
#endif
