#pragma once

#include <QtCore/QtGlobal>

#if defined(SHARED_LIB)
#  define LIB_EXPORT Q_DECL_EXPORT
#else
#  define LIB_EXPORT Q_DECL_IMPORT
#endif

extern "C" {

/**
 * @brief Returns magic number for new order
 */
int LIB_EXPORT magicNumber();

/**
 * @brief Creates context for expert advisor
 * @param id Identifier of this context
 */
void LIB_EXPORT initialize(int id);

/**
 * @brief Removes context of expert advisor
 * Opened connection will be closed
 */
void LIB_EXPORT deinitialize(int id);

/**
 * @brief Connects to server with given name
 */
void LIB_EXPORT connect(int id, const char* server);

/**
 * @brief Registers expert advisor on server
 */
void LIB_EXPORT registerClient(
    int id, const char* strategy, const char* currency,
    const char* timeframe, int digits);

/**
 * @brief Asks server which data are required for decision
 */
void LIB_EXPORT requestUpdate(int id);

int LIB_EXPORT requestedNameCount(int id);
void LIB_EXPORT requestedDataName(int id, int index, char* symbol);
int LIB_EXPORT requestedDataCount(int id, int index);

/**
 * @brief Appends order to data response
 */
void LIB_EXPORT appendOrder(
    int id, const char* event, int magic, int ticket,
    const char* type, double openPrice, double closePrice,
    double lots, double stopLoss, double takeProfit,
    double profit, const char* time, const char* openTime);

/**
 * @brief Appends price data to data response
 */
void LIB_EXPORT appendCandle(
    int id, const char* dateTime, double open, double high,
    double low, double close, long volume);

/**
 * @brief Appends double value to data response
 */
void LIB_EXPORT appendValue(
    int id, const char* name, const char* dateTime, double value);

/**
 * @brief Appends double array to data response
 */
void LIB_EXPORT appendVector(
    int id, const char* name, const char* dateTime,
    double* array, int size);

/**
 * @brief Sends data response to server
 */
void LIB_EXPORT dataResponse(int id);

/**
 * @brief Asks server for trade decision
 * It can be opening of new order or modifying or closing existing one.
 */
void LIB_EXPORT requestDecision(int id);

int LIB_EXPORT orderCount(int id);
void LIB_EXPORT orderCommand(int id, int index, char* command);
int LIB_EXPORT orderTicket(int id, int index);
void LIB_EXPORT orderType(int id, int index, char* type);
double LIB_EXPORT orderLots(int id, int index);
int LIB_EXPORT orderSlippage(int id, int index);
int LIB_EXPORT orderStopLoss(int id, int index);
int LIB_EXPORT orderTakeProfit(int id, int index);
void LIB_EXPORT setOrderError(int id, int index, const char* error);

/**
 * @brief Sends result of execution of trade decision back to server
 */
void LIB_EXPORT decisionStatus(int id);

/**
 * @brief Getter for last error message
 */
void LIB_EXPORT lastError(int id, char* error);

/**
 * @brief Returns true if error occured during last operation
 */
bool LIB_EXPORT hasError(int id);

}


