#include "xtr/xtrServices.h"

struct Message {
  uint32_t type{};
  std::variant<uint32_t, CString> msg{ 0U };

  bool operator==(const Message& rhs) const noexcept { 
    return type == rhs.type && msg == rhs.msg;
  }
  bool operator!=(const Message& rhs) const noexcept {
    return !(*this == rhs);
  }
};

class mockMessenger final : public xtr::MessageManager {
public:
  std::vector<Message> messages;

public:
  void Clear() noexcept { messages.clear(); }

private:
  uint32_t ShowMessage(const CString text, const uint32_t type) override {
    messages.emplace_back(Message{ type, text });
    return 0;
  }
  uint32_t ShowMessage(const uint32_t messageID, const uint32_t type) override {
    messages.emplace_back(Message{ type, messageID });
    return 0;
  }
};

void ExpectMessage(Message expected, std::function<void(void)> functionCall) {
  xtr::Global::Instance().SetMessageManager(std::make_unique<mockMessenger>());

  auto& msger = dynamic_cast<mockMessenger&>(xtr::Global::Msg());
  functionCall();
  ASSERT_EQ(1U, size(msger.messages));
  EXPECT_EQ(expected, *begin(msger.messages));

  xtr::Global::Instance().SetMessageManager(std::make_unique<xtr::MessageManager>());
}