#pragma once

#include "../TradeCore/message.hh"
#include <memory>
#include "database.hh"

/**
 * @brief Used for storing data for logging trades into a database
 */
class LoggerCache
{
public:
    LoggerCache() = default;
    LoggerCache(LoggerCache&& logger) = default;
    LoggerCache& operator=(LoggerCache&& cache) = default;
    void setClient(int clientId, const Registration& registration);
    void setDatabase(std::shared_ptr<Database> database);
    void update(const TradeData& data);

private:
    void lookForFinished(const TradeData& data);
    void lookForChanges(const TradeData& data);
    void cachePrice(const TradeData& data);
    void orderFinished(OrderVector& orderEvents, int magic);

private:
    std::map<int, OrderVector> loggedOrders_;
    CandleVector loggedPrice_;
    TradeData previousData_;
    std::shared_ptr<Database> database_;
    ClientInfo client_;
};
