#pragma once

#include <QString>
#include "../TradeCore/trade_data.hh"

/**
 * @brief Type of message sent between client and server
 */
enum class MessageType {
    Invalid,
    RegistrationRequest,
    StatusReport,
    UpdateRequest,
    UpdateDataRequest,
    UpdateDataResponse,
    DecisionRequest,
    DecisionResponse,
    DecisionStatus
};

QString toString(const MessageType& type);
MessageType messageType(const QString& str);

/**
 * @brief Client registration data
 */
struct Registration {
    QString strategy;
    QString currency;
    QString timeframe;
    int digits;
};

/**
 * @brief Status report data
 */
struct StatusReport {
    QString status;
    QString error;
    MessageType action;
};

/**
 * @brief Used to store parsed messages
 */
struct Message {
    Message() : clientId(-1) {}
    int clientId;
    MessageType type;
    Registration registration;
    StatusReport statusReport;
    DataRequest dataRequest;
    TradeData dataResponse;
    OrderVector tradeDecision;
    OrderVector decisionStatus;
};

/**
 * @brief Parses message from xml string
 */
Message parseMessage(const QString& data);

/**
 * @brief Serializes message to xml string
 */
QString serializeMessage(const Message& message);

/**
 * @brief Creates message for success status report
 */
Message successStatusReport(int clientId, MessageType successOf);

/**
 * @brief Creates message for error status report
 */
Message errorStatusReport(
    int clientId, MessageType errorOf, const QString& errorText);
