/*
 * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <esp_err.h>

#ifdef __cplusplus
extern "C"
{
#endif

/** Function prototype for Controller Callback
 *
 * This function will be invoked by the ESP RainMaker Controller whenever a node data is received.
 * Please do not block in this callback.
 *
 * @param[in] node_id The node ID.
 * @param[in] data The data received from the node.
 * @param[in] data_size The size of the data received from the node.
 * @param[in] priv_data The private data passed in esp_rmaker_controller_enable().
 */
typedef esp_err_t (*esp_rmaker_controller_cb_t) (const char *node_id, const char *data, size_t data_size, void *priv_data);

/** Controller Configuration
 *
 * This structure contains the configuration for the controller service.
 *
 * @param[in] report_node_details Whether to report the node details when the controller service is enabled.
 * @param[in] cb The callback function to be invoked when a node data is received.
 * @param[in] priv_data The private data to be passed to the callback function.
 */
typedef struct {
    bool report_node_details;
    esp_rmaker_controller_cb_t cb;
    void *priv_data;
} esp_rmaker_controller_config_t;

/** Create the controller service
 *
 * This function creates the controller service.
 *
 * @param[in] config The configuration for the controller service.
 *
 * @return ESP_OK on success.
 * @return ESP_FAIL on failure.
 */
esp_err_t esp_rmaker_controller_enable(esp_rmaker_controller_config_t *config);

/** Disable the controller service
 *
 * This function disables the controller service.
 *
 * @return ESP_OK on success.
 * @return ESP_FAIL on failure.
 */
esp_err_t esp_rmaker_controller_disable(void);

/** Get the active group ID
 *
 * This function gets the active group ID.
 *
 * @param[out] group_id The active group ID. Should be freed by the caller.
 *
 * @return ESP_OK on success
 * @return error in case of failure
 */
esp_err_t esp_rmaker_controller_get_active_group_id(char **group_id);

#ifdef __cplusplus
}
#endif
