#pragma once

#include "MQTTAsync.h"
#include <string>

class TransportObserver
{
public:
	virtual void OnConnectServerSuccess(bool success) = 0;
	virtual void OnSubscribeTopicSuccess(bool success) = 0;
	virtual void OnReceiveMessage(std::string message) = 0;
};

class CmdTransportMqtt
{
public:
	CmdTransportMqtt(std::string uu_id, std::string room_id, TransportObserver *observer);

public:
	bool ConnectServer(std::string mqtt);
	bool SendRequest(std::string req);
	void DisConnectServer();

private:
	static void mqtt_onConnectSuccess(void *context, MQTTAsync_successData *response);
	static void mqtt_onConnectFailed(void* context, MQTTAsync_failureData* response);
	
	static void mqtt_subscribeSuccess(void *context, MQTTAsync_successData* response);
	static void mqtt_subscribeFailed(void *context, MQTTAsync_failureData *response);

	static int mqtt_messageArrive(void *context, char *topicName, int len, MQTTAsync_message* message);

private:
	void onConnectServerResult(bool success);
	void onSubscribeResult(bool success);
	void onMessageArrive(MQTTAsync_message* message);

private:
	MQTTAsync	mqtt_client_;
	TransportObserver	*observer_;

private:
	std::string mqtt_url_;
	std::string	uu_id_;
	std::string room_id_;
};