//
//  tb_forwarding_connection_private.h
//  Tightbeam

#ifndef __TIGHTBEAM_FORWARDING_CONNECTION_PRIVATE_H
#define __TIGHTBEAM_FORWARDING_CONNECTION_PRIVATE_H

#include <Tightbeam/tb_connection.h>

#include <sys/cdefs.h>
__ptrcheck_abi_assume_single()

TB_ASSUME_NONNULL_BEGIN
__TB_BEGIN_DECLS

TB_ENUM(tb_forwarding_connection_type, uint32_t,
    TB_FORWARDING_CONNECTION_TYPE_BIDIRECTIONAL TB_SWIFT_NAME(bidirectional) = 0,
    TB_FORWARDING_CONNECTION_TYPE_NON_BLOCKING TB_SWIFT_NAME(nonBlocking)
) TB_SWIFT_NAME(ForwardingConnectionType);

struct tb_forwarding_connection_s {
    bool non_blocking;
    struct tb_connection_s * _Nonnull service;
    struct tb_connection_s * _Nonnull client;
    tb_forwarding_message_handler_b handler;
};

/// Construct a new forward connection object with an options flag and two
/// endpoints; one for receiving Tightbeam messages, and another for sending
/// Tightbeam messages. The receive endpoint will appear as a server
/// connection, and the sending endpoint will appear as a client connection.
///
/// @param endpoint_server
/// The endpoint to receive messages from.
///
/// @param endpoint_client
/// The endpoint to send messages to.
///
/// @param connection_type
/// The type of forwarding connection to configure.
///
/// @discussion
/// The endpoint must wrap the resources needed to bootstrap the specified
/// transport type. This will assert on failure.
TB_EXPORT
tb_forwarding_connection_t
tb_forwarding_connection_create_with_endpoint_options(
        tb_endpoint_t endpoint_server, tb_endpoint_t endpoint_client,
        tb_forwarding_connection_type_t connection_type,
        tb_forwarding_message_handler_b handler);

__TB_END_DECLS
TB_ASSUME_NONNULL_END

#endif // __TIGHTBEAM_FORWARDING_CONNECTION_PRIVATE_H
