#ifndef RPFWD_MANAGER_H
#define RPFWD_MANAGER_H

#include <stdint.h>
#include <stddef.h>

/* ==== Estructura básica de mensaje RPFWD ==== */
typedef struct rpfwd_msg_s {
    uint32_t server_id;
    int exit_flag;
    unsigned char *data;
    size_t data_len;
    uint32_t port;  // Optional port for multi-port RPFWD
} rpfwd_msg_t;

/* ==== Callbacks ==== */
typedef void (*rpfwd_send_cb_t)(
    uint32_t server_id,
    int exit_flag,
    const unsigned char *data,
    size_t data_len,
    uint32_t port,
    void *ctx
);

/* ==== Estado global ==== */
extern volatile int rpfwd_active; // indica si RPFWD está activo

/* ==== API pública ==== */
void rpfwd_manager_init(void);
void rpfwd_manager_cleanup(void);

int rpfwd_manager_process_incoming(
    uint32_t server_id,
    int exit_flag,
    const unsigned char *data,
    size_t data_len,
    uint32_t port
);

void rpfwd_manager_flush_outgoing(rpfwd_send_cb_t cb, void *ctx);

int rpfwd_manager_start_listener(uint16_t local_port);
int rpfwd_manager_stop_listener(void);

#endif /* RPFWD_MANAGER_H */

