using System;
using System.Threading.Tasks;
using Capnp.Rpc;
using FabAccessAPI.Exceptions;
using FabAccessAPI.Schema;
namespace FabAccessAPI
{
///
/// Service to connect to a server and maintain the connection
///
public interface IAPI
{
#region Information about a connection and the server
///
/// State of the conneciton, is the API-Service connecting to a server
///
bool IsConnecting { get; }
///
/// State of the conneciton, is the API-Service connected to a server
///
bool IsConnected { get; }
///
/// Information about the connection
///
/// When API-Service is not connected or trying to connected to a server
ConnectionData ConnectionData { get; }
///
/// Information about the server
/// Is only avalible if the API-Service is connected
///
/// When API-Service is not connected
ServerData ServerData { get; }
#endregion
#region Methods to connect to server
///
/// Connect to server with ConnectionData
/// If connection lost, the API-Server will try to reconnect
///
/// Data to establish a connection to a server
/// When API-Service can not connect to a server
/// When API-Service can connect to a server but can not authenticate
/// When API-Service is allready connected
Task Connect(ConnectionData connectionData, TcpRpcClient tcpRpcClient = null);
///
/// Disconnect from a server
///
/// When API-Service is not connected or trying to connect
Task Disconnect();
///
/// Try to connect to a server and get ServerData
/// The connection is not maintained
///
/// When API-Service can not connect to a server
Task TryToConnect(ConnectionData connectionData, TcpRpcClient tcpRpcClient = null);
#endregion
#region Session
///
/// Get session after connection
///
/// When API-Service is not connected
Session Session { get; }
#endregion
#region Events
///
/// Event on changes in connection status
///
event EventHandler ConnectionStatusChanged;
///
/// Unbind all handlers from EventHandler
///
void UnbindEventHandler();
#endregion
}
}