#pragma once

#include "logger_cache.hh"
#include "../TradeCore/message.hh"
#include "../TradeCore/abstract_strategy.hh"
#include <QTableWidget>
#include <memory>

class Database;
using StrategyPtr = std::unique_ptr<AbstractStrategy>;

/**
 * @brief Stores client informations and strategy
 * Movable because stategy is unique_ptr.
 */
struct Client {
    Client() = default;
    Client(Client&& client) = default;
    Client& operator=(Client&& client) = default;
    StrategyPtr strategy;
    int clientId;
    LoggerCache cache;
};

/**
 * @brief Calls function according to message from client strategy
 * It is also a table widget that displays registered clients.
 */
class CommandProcessor : public QTableWidget
{
    Q_OBJECT

public:
    explicit CommandProcessor(QWidget* parent = nullptr);

    void registerClient(
        int clientId, const Registration& registration, StrategyPtr strategy);

    void removeClient(int identifier);
    void setDatabase(std::shared_ptr<Database> db);

public slots:
    void handleMessage(const Message& message);

signals:
    void sendMessage(const Message& message);

private slots:
    void onCellDoubleClicked(int row, int);

private:
    std::vector<Client> clients_;
    std::shared_ptr<Database> db_;
};
