/**
 * @file link_cable.h
 * @brief Link Cable Manager for 2-Player GameBoy Multiplayer
 */

#pragma once

#include <stdint.h>
#include <stdbool.h>
#include "esp_err.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
    LINK_DISCONNECTED = 0,
    LINK_MASTER,
    LINK_SLAVE
} link_cable_state_t;

/**
 * @brief Initialize Link Cable
 * @return ESP_OK on success
 */
esp_err_t link_cable_init(void);

/**
 * @brief Check if cable is connected
 * @return true if connected
 */
bool link_cable_is_connected(void);

/**
 * @brief Get current link state
 */
link_cable_state_t link_cable_get_state(void);

/**
 * @brief Transfer one byte (send and receive simultaneously)
 * @param data_out Byte to send
 * @return Received byte
 */
uint8_t link_cable_transfer_byte(uint8_t data_out);

/**
 * @brief Get transfer statistics
 * @param tx Bytes sent (can be NULL)
 * @param rx Bytes received (can be NULL)
 * @param err Errors (can be NULL)
 */
void link_cable_get_stats(uint32_t *tx, uint32_t *rx, uint32_t *err);

#ifdef __cplusplus
}
#endif
